結果
問題 | No.1497 Triangle |
ユーザー | square1001 |
提出日時 | 2021-05-03 23:53:38 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,450 bytes |
コンパイル時間 | 1,222 ms |
コンパイル使用メモリ | 95,656 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-22 13:55:11 |
合計ジャッジ時間 | 15,558 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 3 ms
6,944 KB |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 3 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | WA | - |
testcase_23 | AC | 8 ms
6,944 KB |
testcase_24 | AC | 422 ms
6,940 KB |
testcase_25 | AC | 48 ms
6,940 KB |
testcase_26 | AC | 4 ms
6,940 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | AC | 315 ms
6,944 KB |
testcase_33 | WA | - |
testcase_34 | AC | 428 ms
6,944 KB |
testcase_35 | WA | - |
testcase_36 | AC | 514 ms
6,940 KB |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 33 ms
6,944 KB |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
ソースコード
#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<pair<int, int> > > cand(ls); for(int i = 0; i < ls; ++i) { vector<int> orth; for(int j = 0; j < N; ++j) { if(lines[i][0] * X[j] + lines[i][1] * Y[j] + lines[i][2] == 0) { orth.push_back(lines[i][1] * X[j] - lines[i][0] * Y[j]); } } for(int j : orth) { for(int b = 0; b < 2; ++b) { int bit = 0; for(int k = 0; k < N; ++k) { int val = lines[i][0] * X[k] + lines[i][1] * Y[k] + lines[i][2]; if(val == 0) { val += (lines[i][1] * X[k] - lines[i][0] * Y[k] >= j ? +1 : -1) * ((b & 1) ? +1 : -1); } if(val > 0) bit |= 1 << k; } cand[i].push_back(make_pair(+1, bit)); cand[i].push_back(make_pair(-1, (1 << N) - 1 - bit)); } } } 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; for(int k = 0; k < N; ++k) { for(pair<int, int> ci : cand[i]) { for(pair<int, int> cj : cand[j]) { for(pair<int, int> ck : cand[k]) { ok[ci.second & cj.second & ck.second] = 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 = 1LL * lines[p0][2] * (lines[p2][0] * lines[p1][1] - lines[p1][0] * lines[p2][1]); long long val1 = 1LL * lines[p1][2] * (lines[p0][0] * lines[p2][1] - lines[p2][0] * lines[p0][1]); long long val2 = 1LL * 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(pair<int, int> ci : cand[i]) { if(ci.first != sign[0]) continue; for(pair<int, int> cj : cand[j]) { if(cj.first != sign[1]) continue; for(pair<int, int> ck : cand[k]) { if(ck.first != sign[2]) continue; ok[ci.second & cj.second & ck.second] = true; } } } } } } int res = 0; for(int i = 0; i < (1 << N); ++i) { if(ok[i]) { ++res; } } cout << res << endl; return 0; }