結果
問題 | No.3024 等式 |
ユーザー | kimiyuki |
提出日時 | 2017-04-01 02:01:41 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,488 bytes |
コンパイル時間 | 887 ms |
コンパイル使用メモリ | 78,272 KB |
実行使用メモリ | 6,940 KB |
最終ジャッジ日時 | 2024-07-07 15:06:23 |
合計ジャッジ時間 | 3,271 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 16 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | WA | - |
testcase_12 | AC | 23 ms
5,376 KB |
testcase_13 | AC | 21 ms
5,376 KB |
testcase_14 | AC | 22 ms
5,376 KB |
testcase_15 | AC | 3 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 3 ms
5,376 KB |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 1,712 ms
5,376 KB |
ソースコード
#pragma GCC optimize "O3" #pragma GCC target "avx" #include <cstdio> #include <vector> #include <algorithm> #include <array> #include <stack> #include <set> #include <map> #include <queue> #include <tuple> #include <unordered_set> #include <unordered_map> #include <functional> #include <cassert> #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) 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; rational_t() : p(0), q(1) {} rational_t(ll num, ll den = 1) : p(num), q(p ? den : 1) {} rational_t(rational_t const & other) : p(other.p), q(other.q) {} rational_t & operator = (rational_t const & other) { this->p = other.p; this->q = other.q; return *this; } bool operator == (rational_t other) const { return this->p == other.p and 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.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 }; } }; 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]); whole(sort, a); bool found = false; array<rational_t, max_n> x; repeat (i,n) x[i] = rational_t(a[i]); function<void (int)> go = [&](int n) { if (n <= 1) return; repeat (j,n) { swap(x[j], x[n-1]); repeat (i,j) { if (x[i] == x[n-1]) { throw loop_exception {}; } 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; }