結果

問題 No.1017 Reiwa Sequence
ユーザー 👑 kmjpkmjp
提出日時 2020-04-04 02:41:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
J_TLE  
(最初)
実行時間 -
コード長 1,596 bytes
コンパイル時間 1,756 ms
コンパイル使用メモリ 178,736 KB
実行使用メモリ 164,452 KB
最終ジャッジ日時 2023-09-16 05:14:47
合計ジャッジ時間 12,578 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 339 ms
4,376 KB
testcase_01 AC 1,617 ms
4,376 KB
testcase_02 AC 325 ms
4,376 KB
testcase_03 AC 352 ms
4,376 KB
testcase_04 AC 337 ms
4,376 KB
testcase_05 AC 354 ms
4,380 KB
testcase_06 AC 330 ms
4,380 KB
testcase_07 AC 337 ms
4,376 KB
testcase_08 AC 324 ms
4,376 KB
testcase_09 AC 647 ms
55,960 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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];

unordered_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;
}
0