fork download
  1. public class BearDarts {
  2. int gcd(int a, int b) {
  3. return a > 0 ? gcd(b%a,a) : b;
  4. }
  5. Long hash(int a, int b) {
  6. int g = gcd(a, b);
  7. return a/g * 1000L * 1000 * 1001 + b/g;
  8. }
  9. TreeMap<Long,Integer> m = new TreeMap();
  10. void add(int a, int b) {
  11. Long x = hash(a, b);
  12. Integer now = m.get(x);
  13. if(now == null) now = 0;
  14. m.put(x, now + 1);
  15. }
  16. int cnt(int a, int b) {
  17. Long x = hash(a, b);
  18. Integer now = m.get(x);
  19. if(now == null) return 0;
  20. return now;
  21. }
  22. public long count(int[] scores) {
  23. int n = scores.length;
  24. long result = 0;
  25. for(int i = 0; i < n; ++i) {
  26. int c = scores[i];
  27. for(int j = i + 1; j < n; ++j) {
  28. int d = scores[j];
  29. result += cnt(d, c);
  30. }
  31. int b = scores[i];
  32. for(int j = 0; j < i; ++j) {
  33. int a = scores[j];
  34. add(a, b);
  35. }
  36. }
  37. return result;
  38. }
  39. }
  40.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class BearDarts is public, should be declared in a file named BearDarts.java
public class BearDarts {
       ^
Main.java:9: error: cannot find symbol
    TreeMap<Long,Integer> m = new TreeMap();
    ^
  symbol:   class TreeMap
  location: class BearDarts
Main.java:9: error: cannot find symbol
    TreeMap<Long,Integer> m = new TreeMap();
                                  ^
  symbol:   class TreeMap
  location: class BearDarts
3 errors
stdout
Standard output is empty