結果

問題 No.1497 Triangle
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-05-03 22:44:39
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 458 ms / 2,000 ms
コード長 4,809 bytes
コンパイル時間 1,304 ms
コンパイル使用メモリ 158,020 KB
実行使用メモリ 10,168 KB
最終ジャッジ日時 2024-06-22 11:15:52
合計ジャッジ時間 10,129 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 19 ms
6,940 KB
testcase_04 AC 43 ms
6,944 KB
testcase_05 AC 41 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 450 ms
7,476 KB
testcase_23 AC 5 ms
6,940 KB
testcase_24 AC 255 ms
6,944 KB
testcase_25 AC 31 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 458 ms
8,068 KB
testcase_28 AC 249 ms
6,940 KB
testcase_29 AC 135 ms
6,944 KB
testcase_30 AC 7 ms
6,940 KB
testcase_31 AC 8 ms
6,976 KB
testcase_32 AC 232 ms
7,256 KB
testcase_33 AC 216 ms
7,596 KB
testcase_34 AC 296 ms
7,468 KB
testcase_35 AC 300 ms
8,320 KB
testcase_36 AC 339 ms
7,728 KB
testcase_37 AC 345 ms
8,516 KB
testcase_38 AC 277 ms
7,076 KB
testcase_39 AC 286 ms
7,764 KB
testcase_40 AC 361 ms
7,144 KB
testcase_41 AC 365 ms
7,480 KB
testcase_42 AC 406 ms
8,064 KB
testcase_43 AC 396 ms
10,168 KB
testcase_44 AC 28 ms
6,944 KB
testcase_45 AC 269 ms
7,112 KB
testcase_46 AC 311 ms
7,712 KB
testcase_47 AC 353 ms
8,264 KB
testcase_48 AC 394 ms
7,972 KB
testcase_49 AC 433 ms
7,652 KB
testcase_50 AC 458 ms
7,684 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


alias Pt = Tuple!(long, "x", long, "y");

void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto P = new Pt[N];
      foreach (i; 0 .. N) {
        P[i].x = readLong();
        P[i].y = readLong();
      }
      
      if (N <= 1) {
        writeln(1 << N);
        continue;
      }
      
      Pt[] dirs;
      foreach (i; 0 .. N) foreach (j; 0 .. N) {
        if (i != j) {
          long dx = P[j].x - P[i].x;
          long dy = P[j].y - P[i].y;
          const g = gcd(abs(dx), abs(dy));
          dirs ~= Pt(dy / g, -dx / g);
        }
      }
      dirs.sort!((const(Pt) p, const(Pt) q) {
        const sp = (p.y > 0) ? 1 : (p.y < 0) ? 3 : (p.x > 0) ? 0 : 2;
        const sq = (q.y > 0) ? 1 : (q.y < 0) ? 3 : (q.x > 0) ? 0 : 2;
        return ((sp != sq) ? (sp < sq) : (p.x * q.y - p.y * q.x > 0));
      });
      dirs = dirs.uniq.array;
      const dirsLen = cast(int)(dirs.length);
      
      alias PJ = Tuple!(int, "p", int, "j");
      PJ[] pjs;
      foreach (j; 0 .. dirsLen) {
        real t0 = atan2(cast(real)(dirs[j].y), cast(real)(dirs[j].x));
        real t1 = atan2(cast(real)(dirs[(j + 1) % $].y), cast(real)(dirs[(j + 1) % $].x));
        if (t0 > t1) {
          t1 += 2.0L * PI;
        }
        const tMid = (t0 + t1) / 2.0L;
        const xMid = cos(tMid);
        const yMid = sin(tMid);
        alias Entry = Tuple!(real, "val", int, "key");
        auto es = new Entry[N];
        foreach (i; 0 .. N) {
          es[i] = Entry(xMid * P[i].x + yMid * P[i].y, i);
        }
        es.sort;
        debug {
          writefln("(%s, %s): %s", xMid, yMid, es.map!"a.key");
        }
        int p;
        foreach (i; 0 .. N) {
          if (i > 0) {
            pjs ~= PJ(p, j);
          }
          p |= 1 << es[i].key;
        }
      }
      pjs.sort;
      const pjsLen = cast(int)(pjs.length);
      
      alias PJJ = Tuple!(int, "p", int, "j0", int, "j1");
      PJJ[] pjjs;
      for (int e = 0, f; e < pjsLen; e = f) {
        for (f = e; f < pjsLen && pjs[e].p == pjs[f].p; ++f) {}
        int j0 = -1, j1 = -1;
        foreach (g; e .. f - 1) {
          if (pjs[g].j + 1 < pjs[g + 1].j) {
            j0 = pjs[g + 1].j;
            j1 = pjs[g].j + 1 + dirsLen;
          }
        }
        if (j0 == -1) {
          j0 = pjs[e].j;
          j1 = pjs[f - 1].j + 1;
        }
        pjjs ~= PJJ(pjs[e].p, j0, j1);
      }
      const pjjsLen = cast(int)(pjjs.length);
      debug {
        writeln("pjjs = ", pjjs);
      }
      
      auto used = new bool[1 << N];
      used[0] = used[$ - 1] = true;
      foreach (k0; 0 .. pjjsLen) {
        used[pjjs[k0].p] = true;
      }
      foreach (k0; 0 .. pjjsLen) foreach (k1; k0 .. pjjsLen) {
        used[pjjs[k0].p | pjjs[k1].p] = true;
      }
      foreach (k0; 0 .. pjjsLen) foreach (k1; k0 .. pjjsLen) foreach (k2; k1 .. pjjsLen) {
        PJJ[5] ts = [pjjs[k0], pjjs[k1], pjjs[k2], pjjs[k0], pjjs[k1]];
        bool ok = true;
        foreach (l; 0 .. 3) {
          const lb = ts[l].j0;
          const ub = ts[l].j0 + dirsLen / 2;
          if (
              ((lb <= ts[l + 1].j0 && ts[l + 1].j1 <= ub) ||
               (lb <= ts[l + 1].j0 + dirsLen && ts[l + 1].j1 + dirsLen <= ub)) &&
              ((lb <= ts[l + 2].j0 && ts[l + 2].j1 <= ub) ||
               (lb <= ts[l + 2].j0 + dirsLen && ts[l + 2].j1 + dirsLen <= ub))
          ) {
            ok = false;
            break;
          }
        }
        if (ok) {
          used[ts[0].p | ts[1].p | ts[2].p] = true;
        }
      }
      
      const ans = cast(int)(used.count(true));
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0