結果
問題 | No.1497 Triangle |
ユーザー | square1001 |
提出日時 | 2021-05-03 23:09:18 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,199 bytes |
コンパイル時間 | 1,442 ms |
コンパイル使用メモリ | 99,120 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-07-22 13:20:45 |
合計ジャッジ時間 | 7,684 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,752 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 8 ms
5,376 KB |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 4 ms
5,376 KB |
testcase_22 | TLE | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
ソースコード
#include <vector> #include <iostream> #include <algorithm> using namespace std; int gcd(int x, int y) { if(y == 0) return x; return gcd(y, x % y); } int main() { int N; cin >> N; vector<int> X(N), Y(N); for(int i = 0; i < N; ++i) { cin >> X[i] >> Y[i]; } vector<vector<int> > lines; // {a, b, c} --> ax + by + c = 0 for(int i = 0; i < N; ++i) { for(int j = 0; j < i; ++j) { int a = Y[i] - Y[j]; int b = -(X[i] - X[j]); int c = -(a * X[i] + b * Y[i]); int g = gcd(abs(a), gcd(abs(b), abs(c))); if(a < 0 || (a == 0 && b < 0)) { a *= -1, b *= -1, c *= -1; } lines.push_back({a / g, b / g, c / g}); } } sort(lines.begin(), lines.end()); lines.erase(unique(lines.begin(), lines.end()), lines.end()); int ls = lines.size(); vector<bool> ok(1 << N, false); ok[0] = true; for(int i = 0; i < N; ++i) { ok[1 << i] = true; } vector<vector<int> > online(ls), orth(ls); for(int i = 0; i < ls; ++i) { for(int j = 0; j < N; ++j) { if(lines[i][0] * X[j] + lines[i][1] * Y[j] + lines[i][2] == 0) { online[i].push_back(j); orth[i].push_back(lines[i][1] * X[j] - lines[i][0] * Y[j]); } } sort(online[i].begin(), online[i].end(), [&](int va, int vb) { return lines[i][1] * (X[vb] - X[va]) - lines[i][0] * (Y[vb] - Y[va]) > 0; }); sort(orth[i].begin(), orth[i].end()); } for(int i = 0; i < ls; ++i) { for(int j = 0; j < i; ++j) { if(lines[i][0] * lines[j][1] != lines[i][1] * lines[j][0]) continue; bool swapflag = false; if(lines[i][2] > lines[j][2]) { swap(i, j); swapflag = true; } for(int k = 0; k < ls; ++k) { if(lines[j][0] * lines[k][1] == lines[j][1] * lines[k][0]) continue; if(lines[k][0] * lines[i][1] == lines[k][1] * lines[i][0]) continue; vector<int> sign = { -1, +1, 0 }; for(int w1 : orth[i]) { for(int w2 : orth[j]) { for(int w3 : orth[k]) { for(int b = 0; b < 16; ++b) { sign[2] = ((b & 8) ? +1 : -1); int bit = 0; for(int l = 0; l < N; ++l) { int vali = lines[i][0] * X[l] + lines[i][1] * Y[l] + lines[i][2]; int valj = lines[j][0] * X[l] + lines[j][1] * Y[l] + lines[j][2]; int valk = lines[k][0] * X[l] + lines[k][1] * Y[l] + lines[k][2]; if(vali == 0) vali += (lines[i][1] * X[l] - lines[i][0] * Y[l] >= w1 ? +1 : -1) * ((b & 1) ? +1 : -1); if(valj == 0) valj += (lines[j][1] * X[l] - lines[j][0] * Y[l] >= w2 ? +1 : -1) * ((b & 2) ? +1 : -1); if(valk == 0) valk += (lines[k][1] * X[l] - lines[k][0] * Y[l] >= w3 ? +1 : -1) * ((b & 4) ? +1 : -1); if(vali * sign[0] >= 0 && valj * sign[1] >= 0 && valk * sign[2] >= 0) { bit |= 1 << l; } } // cout << i << ' ' << j << ' ' << bit << endl; ok[bit] = true; } } } } } if(swapflag) { swap(i, j); } } } for(int i = 0; i < ls; ++i) { int sz = online[i].size(); for(int j = 0; j <= sz; ++j) { for(int k = j + 1; k <= sz; ++k) { int bit = 0; for(int l = j; l < k; ++l) { bit |= 1 << online[i][l]; } ok[bit] = true; } } } for(int i = 0; i < ls; ++i) { for(int j = 0; j < i; ++j) { for(int k = 0; k < j; ++k) { if(lines[i][0] * lines[j][1] == lines[i][1] * lines[j][0]) continue; if(lines[j][0] * lines[k][1] == lines[j][1] * lines[k][0]) continue; if(lines[k][0] * lines[i][1] == lines[k][1] * lines[i][0]) continue; vector<int> pos = { i, j, k }; vector<int> sign(3); bool nonzero = true; for(int w = 0; w < 3; ++w) { int p0 = pos[w], p1 = pos[(w + 1) % 3], p2 = pos[(w + 2) % 3]; long long val0 = lines[p0][2] * (lines[p2][0] * lines[p1][1] - lines[p1][0] * lines[p2][1]); long long val1 = lines[p1][2] * (lines[p0][0] * lines[p2][1] - lines[p2][0] * lines[p0][1]); long long val2 = lines[p2][2] * (lines[p0][0] * lines[p1][1] - lines[p1][0] * lines[p0][1]); long long val = (val0 + val1 - val2) * (lines[p2][0] * lines[p1][1] - lines[p1][0] * lines[p2][1] > 0 ? +1 : -1); if(val == 0) { nonzero = false; break; } sign[w] = (val > 0 ? +1 : -1); } if(!nonzero) continue; for(int w1 : orth[i]) { for(int w2 : orth[j]) { for(int w3 : orth[k]) { for(int b = 0; b < 8; ++b) { int bit = 0; for(int l = 0; l < N; ++l) { int vali = lines[i][0] * X[l] + lines[i][1] * Y[l] + lines[i][2]; int valj = lines[j][0] * X[l] + lines[j][1] * Y[l] + lines[j][2]; int valk = lines[k][0] * X[l] + lines[k][1] * Y[l] + lines[k][2]; if(vali == 0) vali += (lines[i][1] * X[l] - lines[i][0] * Y[l] >= w1 ? +1 : -1) * ((b & 1) ? +1 : -1); if(valj == 0) valj += (lines[j][1] * X[l] - lines[j][0] * Y[l] >= w2 ? +1 : -1) * ((b & 2) ? +1 : -1); if(valk == 0) valk += (lines[k][1] * X[l] - lines[k][0] * Y[l] >= w3 ? +1 : -1) * ((b & 4) ? +1 : -1); if(vali * sign[0] >= 0 && valj * sign[1] >= 0 && valk * sign[2] >= 0) { bit |= 1 << l; } } ok[bit] = true; } } } } } } } int res = 0; for(int i = 0; i < (1 << N); ++i) { if(ok[i]) { ++res; } } cout << res << endl; return 0; }