結果
| 問題 |
No.1497 Triangle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-03 21:03:04 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 4,342 bytes |
| コンパイル時間 | 1,238 ms |
| コンパイル使用メモリ | 150,620 KB |
| 実行使用メモリ | 34,196 KB |
| 最終ジャッジ日時 | 2024-06-22 11:15:17 |
| 合計ジャッジ時間 | 9,093 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 TLE * 2 -- * 28 |
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/numeric.d(2999): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`
ソースコード
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);
auto pss = new int[][](dirsLen, 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");
auto es = new Entry[N];
foreach (i; 0 .. N) {
es[i] = Entry(xMid * P[i].x + yMid * P[i].y, i);
}
es.sort;
pss[j][0] = 0;
foreach (i; 0 .. N) {
pss[j][i + 1] = pss[j][i] | 1 << es[i].key;
}
debug {
writefln("(%s, %s): %s", xMid, yMid, es.map!"a.key");
}
}
auto itvls = new int[][][](dirsLen + 1, dirsLen + 1);
foreach (j0; 0 .. dirsLen + 1) foreach (j1; j0 + 1 .. dirsLen + 1) {
foreach (j; j0 .. j1) {
itvls[j0][j1] ~= pss[j];
}
itvls[j0][j1] = itvls[j0][j1].sort.uniq.array;
}
auto used = new bool[1 << N];
/*
foreach (j0; 0 .. dirsLen) foreach (j1; j0 .. dirsLen) foreach (j2; j1 .. dirsLen) {
if (j2 < j0 + dirsLen / 2) continue;
if (j0 + dirsLen < j1 + dirsLen / 2) continue;
if (j1 + dirsLen < j2 + dirsLen / 2) continue;
foreach (i0; 0 .. N + 1) foreach (i1; 0 .. N + 1) foreach (i2; 0 .. N + 1) {
used[pss[j0][i0] | pss[j1][i1] | pss[j2][i2]] = true;
}
}
*/
foreach (j0; 0 .. dirsLen) foreach (j2; j0 .. dirsLen) {
int[] j1s;
foreach (j1; j0 .. j2 + 1) {
if (j2 < j0 + dirsLen / 2) continue;
if (j0 + dirsLen < j1 + dirsLen / 2) continue;
if (j1 + dirsLen < j2 + dirsLen / 2) continue;
j1s ~= j1;
}
if (!j1s.empty) {
foreach (i0; 0 .. N + 1) foreach (i2; 0 .. N + 1) {
foreach (p1; itvls[j1s[0]][j1s[$ - 1] + 1]) {
used[pss[j0][i0] | pss[j2][i2] | p1] = true;
}
}
}
}
const ans = cast(int)(used.count(true));
writeln(ans);
}
} catch (EOFException e) {
}
}