結果
問題 | No.8024 等式 |
ユーザー | kimiyuki |
提出日時 | 2017-04-01 02:12:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,009 bytes |
コンパイル時間 | 548 ms |
コンパイル使用メモリ | 56,576 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-30 04:13:12 |
合計ジャッジ時間 | 2,607 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 WA * 1 |
ソースコード
#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 ll = long long; using namespace std; // ll gcd(ll a, ll b) { while (a) { b %= a; swap(a, b); } return b; } struct rational_t { ll p, q; 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 { ll num = this->p * other.q - other.p * this->q; return { num, num ? this->q * other.q : 1 }; } 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(ll p, ll q) { return { p, q }; } constexpr int max_n = 7; struct loop_exception {}; int main() { int n; scanf("%d", &n); vector<int> a(n); repeat (i,n) scanf("%d", &a[i]); bool found = false; array<rational_t, max_n> x; repeat (i,n) 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(n); } catch (loop_exception e) { found = true; } printf("%s\n", found ? "YES" : "NO"); return 0; }