結果
問題 | No.3024 等式 |
ユーザー | kimiyuki |
提出日時 | 2017-04-01 02:45:42 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,992 bytes |
コンパイル時間 | 534 ms |
コンパイル使用メモリ | 57,728 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-30 04:13:33 |
合計ジャッジ時間 | 2,218 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 12 ms
6,940 KB |
testcase_13 | AC | 12 ms
6,940 KB |
testcase_14 | AC | 13 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 3 ms
6,944 KB |
testcase_17 | AC | 5 ms
6,940 KB |
testcase_18 | AC | 3 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | WA | - |
testcase_22 | AC | 887 ms
6,940 KB |
ソースコード
#pragma GCC optimize "O3" #pragma GCC target "avx" #include <cstdio> #include <vector> #include <array> #include <functional> #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) using namespace std; struct rational_t { double p, q; // q may be 0 bool operator == (rational_t other) const { return this->p * other.q == this->q * other.p; } rational_t operator + (rational_t other) const { return { this->p * other.q + other.p * this->q, this->q * other.q }; } rational_t operator - (rational_t other) const { return { this->p * other.q - other.p * this->q, this->q * other.q }; } rational_t operator * (rational_t other) const { return { this->p * other.p, this->q * other.q }; } rational_t operator / (rational_t other) const { return { this->p * other.q, this->q * other.p }; } }; rational_t make_rational(double p, double q) { return { p, q }; } constexpr int max_n = 7; struct loop_exception {}; bool solve(vector<int> const & a) { array<rational_t, max_n> x; repeat (i, a.size()) x[i] = make_rational(a[i], 1); function<void (int)> go = [&](int n) { repeat (j,n) { swap(x[j], x[n-1]); repeat (i,j) { if (x[i] == x[n-1]) { throw loop_exception {}; } if (n == 2) continue; rational_t saved = x[i]; x[i] = saved + x[n-1]; go(n-1); x[i] = saved - x[n-1]; go(n-1); x[i] = saved * x[n-1]; go(n-1); if (x[n-1].p) { x[i] = saved / x[n-1]; go(n-1); } x[i] = saved; } swap(x[j], x[n-1]); } }; try { go(a.size()); } catch (loop_exception e) { return true; } return false; } int main() { int n; scanf("%d", &n); vector<int> a(n); repeat (i,n) scanf("%d", &a[i]); bool found = solve(a); printf("%s\n", found ? "YES" : "NO"); return 0; }