結果
問題 | No.8024 等式 |
ユーザー |
|
提出日時 | 2017-04-01 00:45:59 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,353 bytes |
コンパイル時間 | 881 ms |
コンパイル使用メモリ | 80,140 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-07-07 14:29:35 |
合計ジャッジ時間 | 12,339 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 TLE * 1 -- * 10 |
ソースコード
#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 repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i)) #define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i)) #define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) #define debug(x) #x << " = " << (x) << " " using ll = long long; using namespace std; template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); } template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } ll gcd(ll a, ll b) { while (a) { b %= a; swap(a, b); } return b; } pair<ll, ll> make_rational(ll num, ll den) { ll d = gcd(num, den); return make_pair(num / d, den / d); } pair<ll, ll> operator + (pair<ll, ll> x, pair<ll, ll> y) { return make_rational(x.first * y.second + y.first * x.second, x.second * y.second); } pair<ll, ll> operator - (pair<ll, ll> x, pair<ll, ll> y) { return make_rational(x.first * y.second - y.first * x.second, x.second * y.second); } pair<ll, ll> operator * (pair<ll, ll> x, pair<ll, ll> y) { return make_rational(x.first * y.first, x.second * y.second); } pair<ll, ll> operator / (pair<ll, ll> x, pair<ll, ll> y) { return make_rational(x.first * y.second, x.second * y.first); } constexpr int max_n = 7; int main() { int n; scanf("%d", &n); vector<int> a(n); repeat (i,n) scanf("%d", &a[i]); bool found = false; array<pair<ll, ll>, 2*max_n-1> s; repeat (i,n) s[i] = { ll(a[i]), 1 }; repeat_from (i,n,max_n) s[i] = { -1, 0 }; repeat(i,max_n-1) s[max_n+i] = { -2, 0 }; whole(sort, s); do { stack<pair<ll,ll> > stk; int i = 0; function<void ()> go = [&]() { if (found) return; if (s[i] == make_pair<ll, ll>(-1, 0)) { // invalid } else if (s[i] == make_pair<ll, ll>(-2, 0)) { // op if (stk.size() >= 2) { pair<ll,ll> y = stk.top(); stk.pop(); pair<ll,ll> x = stk.top(); stk.pop(); if (x == y) { found = true; } ++ i; stk.push(x + y); go(); stk.pop(); stk.push(x - y); go(); stk.pop(); stk.push(x * y); go(); stk.pop(); stk.push(x / y); go(); stk.pop(); -- i; stk.push(x); stk.push(y); } } else { stk.push(s[i]); ++ i; go(); -- i; stk.pop(); } }; go(); } while(whole(next_permutation, s)); printf("%s\n", found ? "YES" : "NO"); return 0; }