結果
問題 | No.8024 等式 |
ユーザー |
![]() |
提出日時 | 2017-03-31 23:55:10 |
言語 | C++11 (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,454 bytes |
コンパイル時間 | 1,414 ms |
コンパイル使用メモリ | 177,324 KB |
実行使用メモリ | 37,804 KB |
最終ジャッジ日時 | 2024-07-07 06:46:25 |
合計ジャッジ時間 | 8,324 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 TLE * 1 -- * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:104:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 104 | scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:105:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 105 | REP(i,n)scanf("%d",a+i); | ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "<<x<<endl int n; int a[7]; namespace std{ template <> class hash<pll> { public: size_t operator()(const pll &x) const { return hash<int>()(hash<int>()(x.first)) ^ hash<int>()(x.second); } }; } unordered_map<pll,vi> M; unordered_set<pll> S; vector<pll> V; void dfs(int mask){ if(mask==0 && V.size()==1){ ll g = __gcd(V[0].first, V[0].second); S.insert(pll(V[0].first/g,V[0].second/g)); return; } if(mask != 0){ // push REP(i,n)if((mask>>i)&1){ int nmsk = mask ^ (1<<i); V.push_back(pll(a[i],1)); dfs(nmsk); V.pop_back(); } } if(V.size()>=2){ // pop pll x = V.back(); V.pop_back(); pll y = V.back(); V.pop_back(); ll xa = x.first; ll xb = x.second; ll ya = y.first; ll yb = y.second; // add { ll zb = xb*yb; ll za = xa*yb + ya*xb; V.push_back(pll(za,zb)); dfs(mask); V.pop_back(); } // sub { ll zb = xb*yb; ll za = xa*yb - ya*xb; V.push_back(pll(za,zb)); dfs(mask); V.pop_back(); } // mul { ll za = xa*ya; ll zb = xb*yb; if(zb<0){ zb*=-1; za*=-1; } V.push_back(pll(za,zb)); dfs(mask); V.pop_back(); } // div if(ya!=0){ ll za = xa*yb; ll zb = xb*ya; if(zb<0){ zb*=-1; za*=-1; } V.push_back(pll(za,zb)); dfs(mask); V.pop_back(); } V.push_back(y); V.push_back(x); } } int main(){ scanf("%d",&n); REP(i,n)scanf("%d",a+i); REP(mask,1<<n){ int po = __builtin_popcount(mask); if(po==0 || po==7)continue; S.clear(); V.clear(); dfs(mask); for(pll x : S){ for(int another : M[x]){ if((mask&another)==0){ puts("YES"); // DEBUG(mask); // DEBUG(another); // DEBUG(x.first); // DEBUG(x.second); return 0; } } M[x].push_back(mask); } } puts("NO"); return 0; }