結果

問題 No.1497 Triangle
ユーザー 👑 hos.lyrichos.lyric
提出日時 2021-05-03 20:32:09
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 3,661 bytes
コンパイル時間 1,165 ms
コンパイル使用メモリ 149,416 KB
実行使用メモリ 37,680 KB
最終ジャッジ日時 2024-06-22 11:14:43
合計ジャッジ時間 7,829 ms
ジャッジサーバーID
(参考情報)
judge5 / 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 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 WA -
testcase_23 AC 2 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
6,940 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 247 ms
35,916 KB
testcase_33 AC 248 ms
36,696 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 3 ms
6,944 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/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();
      }
      
      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);
      
      int[] masks;
      masks ~= 0;
      masks ~= (1 << N) - 1;
      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");
        */
        const xMid = dirs[j].x + dirs[(j + 1) % $].x;
        const yMid = dirs[j].y + dirs[(j + 1) % $].y;
        alias Entry = Tuple!(long, "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;
        int p;
        foreach (i; 0 .. N) {
          p |= 1 << es[i].key;
          masks ~= p;
        }
        debug {
          writefln("(%s, %s): %s", xMid, yMid, es.map!"a.key");
        }
      }
      masks.sort.uniq.array;
      const masksLen = cast(int)(masks.length);
      debug {
        writeln("|masks| = ", masks.length);
      }
      
      auto fs = new long[1 << N];
      foreach (p; masks) {
        fs[p] = 1;
      }
      foreach (i; 0 .. N) foreach (p; 0 .. 1 << N) if (!(p & 1 << i)) fs[p | 1 << i] += fs[p];
      foreach (p; 0 .. 1 << N) {
        fs[p] = fs[p] * fs[p] * fs[p];
      }
      foreach (i; 0 .. N) foreach (p; 0 .. 1 << N) if (!(p & 1 << i)) fs[p | 1 << i] -= fs[p];
      
      const ans = cast(int)(fs.count!"a > 0");
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0