Submission #941634


Source Code Expand

import java.util.*;
public class Main {
  void run() {
    int n = ni();
    int[] x = new int[n];
    int[] y = new int[n];
    for (int i = 0; i < n; ++i) {
      x[i] = ni();
      y[i] = ni();
    }

    long cnt90 = 0;
    long cntdon = 0;
    for (int i = 0; i < n; ++i) {
      // 点iを基準Bとする。
      ArrayList<Vec> list = new ArrayList<>();
      for (int j = 0; j < n; ++j) {
        if (i == j) continue;
        Vec vec = new Vec(j, x[j] - x[i], y[j] - y[i]);
        Vec vec2 = new Vec(j, x[j] - x[i], y[j] - y[i], 2 * Math.PI);
        list.add(vec);
        list.add(vec2);
      }
      Collections.sort(list, new Comparator<Vec>() {
        @Override
        public int compare(Vec o1, Vec o2) {
          return Double.compare(o1.arc, o2.arc);
        }
      });
      for (int j = 0; j < n - 1; ++j) {
        // 点jを基準Aとする
        Vec atom = list.get(j);
        // <ABCが2/pi以上で最小な点を探す
        int left = 0;
        int right = list.size();
        while (right - left > 1) {
          int mid = (left + right) / 2;
          Vec trg = list.get(mid);
          if (trg.arc - atom.arc - 1e-9 > Math.PI / 2.0) {
            right = mid;
          } else {
            left = mid;
          }
        }
        int idx90 = (left + right) / 2;
        if (Math.abs(Math.PI / 2.0 - (list.get(idx90).arc - atom.arc)) < 1e-9) {
          ++cnt90;
        }
        // <ABCがpi以下で最大な点を探す
        left = 0;
        right = list.size();
        while (right - left > 1) {
          int mid = (left + right) / 2;
          Vec trg = list.get(mid);
          if (trg.arc - atom.arc > Math.PI - 1e-9) {
            right = mid;
          } else {
            left = mid;
          }
        }
        int idx180 = (left + right) / 2;
        cntdon += idx180 - idx90;
      }
    }
    long cntei = (long) n * (n - 1) * (n - 2) / 6;
    cntei -= cnt90 + cntdon;
    System.out.println(cntei + " " + cnt90 + " " + cntdon);
  }

  class Vec {
    int id;
    int x, y;
    double arc;

    Vec(int id, int x, int y, double add) {
      this.id = id;
      this.x = x;
      this.y = y;
      arc = Math.atan2(y, x) + add;
    }

    Vec(int id, int x, int y) {
      this(id, x, y, 0);
    }

    @Override
    public String toString() {
      return "{id = " + id + ", arc = " + (arc * 180.0 / Math.PI) + "}";
    }
  }

  Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    new Main().run();
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Submission Info

Submission Time
Task D - 三角形の分類
User arukuka
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 2753 Byte
Status AC
Exec Time 3055 ms
Memory 95112 KB

Judge Result

Set Name sample subtask01 subtask02
Score / Max Score 0 / 0 30 / 30 70 / 70
Status
AC × 2
AC × 28
AC × 54
Set Name Test Cases
sample sample-01.txt, sample-02.txt
subtask01 01-00.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-handmade00.txt, 01-handmade01.txt, 01-handmade02.txt, 01-handmade03.txt, 01-handmade04.txt, 01-handmade05.txt, sample-01.txt, sample-02.txt
subtask02 01-00.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-handmade00.txt, 01-handmade01.txt, 01-handmade02.txt, 01-handmade03.txt, 01-handmade04.txt, 01-handmade05.txt, 02-00.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-handmade00.txt, 02-handmade01.txt, 02-handmade02.txt, 02-handmade03.txt, 02-handmade04.txt, 02-handmade05.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-00.txt AC 350 ms 24184 KB
01-01.txt AC 343 ms 24188 KB
01-02.txt AC 386 ms 24240 KB
01-03.txt AC 369 ms 24180 KB
01-04.txt AC 361 ms 24184 KB
01-05.txt AC 398 ms 25368 KB
01-06.txt AC 377 ms 25264 KB
01-07.txt AC 442 ms 30212 KB
01-08.txt AC 441 ms 30236 KB
01-09.txt AC 448 ms 30440 KB
01-10.txt AC 452 ms 30800 KB
01-11.txt AC 446 ms 30576 KB
01-12.txt AC 461 ms 30512 KB
01-13.txt AC 467 ms 30120 KB
01-14.txt AC 463 ms 30192 KB
01-15.txt AC 488 ms 31112 KB
01-16.txt AC 478 ms 31124 KB
01-17.txt AC 456 ms 30676 KB
01-18.txt AC 476 ms 31448 KB
01-19.txt AC 452 ms 30556 KB
01-handmade00.txt AC 386 ms 26344 KB
01-handmade01.txt AC 461 ms 31232 KB
01-handmade02.txt AC 405 ms 28008 KB
01-handmade03.txt AC 446 ms 29928 KB
01-handmade04.txt AC 452 ms 30240 KB
01-handmade05.txt AC 474 ms 30588 KB
02-00.txt AC 585 ms 35392 KB
02-01.txt AC 719 ms 45456 KB
02-02.txt AC 756 ms 46132 KB
02-03.txt AC 939 ms 45732 KB
02-04.txt AC 915 ms 46276 KB
02-05.txt AC 980 ms 46320 KB
02-06.txt AC 1253 ms 63232 KB
02-07.txt AC 1255 ms 62068 KB
02-08.txt AC 1257 ms 62868 KB
02-09.txt AC 1230 ms 62744 KB
02-10.txt AC 1272 ms 63324 KB
02-11.txt AC 1251 ms 62716 KB
02-12.txt AC 1252 ms 63124 KB
02-13.txt AC 3024 ms 94520 KB
02-14.txt AC 3006 ms 95112 KB
02-15.txt AC 3046 ms 94432 KB
02-16.txt AC 3055 ms 94852 KB
02-17.txt AC 2964 ms 94340 KB
02-18.txt AC 3007 ms 94428 KB
02-19.txt AC 2921 ms 94288 KB
02-handmade00.txt AC 1767 ms 93112 KB
02-handmade01.txt AC 2977 ms 94392 KB
02-handmade02.txt AC 2014 ms 93264 KB
02-handmade03.txt AC 3005 ms 94612 KB
02-handmade04.txt AC 2963 ms 93980 KB
02-handmade05.txt AC 3026 ms 94488 KB
sample-01.txt AC 339 ms 24184 KB
sample-02.txt AC 337 ms 24072 KB