fork download
  1. import static java.lang.Integer.max;
  2.  
  3. public class TwoDiagonals {
  4.  
  5. public int maxPoints(int[] x, int[] y) {
  6. int n = x.length;
  7. int max_coord = 0;
  8. for(int i = 0; i < n; ++i) {
  9. max_coord = max(max_coord, max(x[i], y[i]));
  10. }
  11. max_coord++;
  12. boolean[][] grid = new boolean[max_coord][max_coord];
  13. int[] cnt_sum = new int[2*max_coord+1];
  14. int[] cnt_diff = new int[2*max_coord+1];
  15. for(int i = 0; i < n; ++i) {
  16. grid[x[i]][y[i]] = true;
  17. cnt_sum[x[i]+y[i]]++;
  18. cnt_diff[x[i]-y[i]+max_coord]++;
  19. }
  20. int answer = 0;
  21. for(int sum = 0; sum < cnt_sum.length; ++sum)
  22. for(int diff = 0; diff < cnt_diff.length; ++diff) {
  23. int together = cnt_sum[sum] + cnt_diff[diff];
  24. // x + y = sum
  25. // x - y = diff - max_coord
  26. int x2 = sum + diff - max_coord;
  27. int y2 = sum - diff + max_coord;
  28. if(x2 % 2 == 0 && y2 % 2 == 0) {
  29. int x1 = x2 / 2;
  30. int y1 = y2 / 2;
  31. if(0 <= x1 && x1 < max_coord && 0 <= y1 && y1 < max_coord && grid[x1][y1])
  32. --together;
  33. }
  34. answer = max(answer, together);
  35. }
  36. return answer;
  37. }
  38. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: class TwoDiagonals is public, should be declared in a file named TwoDiagonals.java
public class TwoDiagonals {
       ^
1 error
stdout
Standard output is empty