結果
問題 |
No.1017 Reiwa Sequence
|
ユーザー |
![]() |
提出日時 | 2020-04-04 02:38:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
J_TLE
(最初)
|
実行時間 | - |
コード長 | 1,586 bytes |
コンパイル時間 | 1,761 ms |
コンパイル使用メモリ | 181,720 KB |
実行使用メモリ | 155,296 KB |
最終ジャッジ日時 | 2024-07-03 06:45:34 |
合計ジャッジ時間 | 15,309 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 TLE * 1 -- * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N; int A[151515]; map<int,vector<int>> V; vector<int> R; void dfs(int cur,int sum) { if(R.size()==15) { V[sum]=R; return; } R.push_back(0); dfs(cur+1,sum); R.back()=A[cur]; dfs(cur+1,sum+A[cur]); R.back()=-A[cur]; dfs(cur+1,sum-A[cur]); R.pop_back(); } void dfs2(int cur,int sum) { if(R.size()==15) { if(V.count(-sum)) { vector<int> R2=V[-sum]; int ok=0; FORR(r,R) if(r!=0) ok++; FORR(r,R2) if(r!=0) ok++; if(ok) { int i; cout<<"Yes"<<endl; FOR(i,N) { if(i<15) cout<<R2[i]<<" "; else if(i<30) cout<<R[i-15]<<" "; else cout<<"0 "; } exit(0); } } return; } R.push_back(0); dfs2(cur+1,sum); R.back()=A[cur]; dfs2(cur+1,sum+A[cur]); R.back()=-A[cur]; dfs2(cur+1,sum-A[cur]); R.pop_back(); } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) cin>>A[i]; dfs(0,0); dfs2(15,0); cout<<"No"<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }