結果

問題 No.1017 Reiwa Sequence
ユーザー chocoruskchocorusk
提出日時 2020-04-03 22:14:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,263 bytes
コンパイル時間 1,431 ms
コンパイル使用メモリ 123,524 KB
実行使用メモリ 523,576 KB
最終ジャッジ日時 2023-09-16 02:16:33
合計ジャッジ時間 15,119 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 4 ms
6,928 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
7,284 KB
testcase_06 AC 4 ms
6,936 KB
testcase_07 AC 2 ms
5,388 KB
testcase_08 AC 2 ms
5,380 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 3 ms
6,348 KB
testcase_14 AC 110 ms
27,668 KB
testcase_15 AC 346 ms
64,236 KB
testcase_16 AC 121 ms
30,240 KB
testcase_17 AC 1,950 ms
266,900 KB
testcase_18 AC 116 ms
28,872 KB
testcase_19 TLE -
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 <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	int a[150010], c[150010];
	int p=-1, q=-1;
	fill(c, c+150001, -1);
	for(int i=0; i<n; i++){
		cin>>a[i];
		if(c[a[i]]==-1){
			c[a[i]]=i;
		}else{
			p=c[a[i]], q=i;
			break;
		}
	}
	if(n==1){
		cout<<"No"<<endl;
		return 0;
	}
	if(p!=-1){
		cout<<"Yes"<<endl;
		for(int i=0; i<n; i++){
			if(i==p) cout<<a[i]<<" ";
			else if(i==q) cout<<-a[i]<<" ";
			else cout<<0<<" ";
		}
		cout<<endl;
		return 0;
	}
	int p2, q2;
	P s[300030];
	fill(s, s+300001, P(-1, -1));
	for(int i=0; i<n; i++){
		for(int j=0; j<i; j++){
			if(s[a[i]+a[j]]==P(-1, -1)){
				s[a[i]+a[j]]=P(j, i);
			}else{
				p=j, q=i, p2=s[a[i]+a[j]].first, q2=s[a[i]+a[j]].second;
				break;
			}
		}
		if(p!=-1) break;
	}
	if(p!=-1){
		cout<<"Yes"<<endl;
		for(int i=0; i<n; i++){
			if(i==p || i==q) cout<<a[i]<<" ";
			else if(i==p2 || i==q2) cout<<-a[i]<<" ";
			else cout<<0<<" ";
		}
		cout<<endl;
		return 0;
	}
	for(int j=0; j<n; j++){
		if(s[a[j]]!=P(-1, -1)){
			p2=s[a[j]].first, q2=s[a[j]].second;
			cout<<"Yes"<<endl;
			for(int i=0; i<n; i++){
				if(i==j) cout<<a[i]<<" ";
				else if(i==p2 || i==q2) cout<<-a[i]<<" ";
				else cout<<0<<" ";
			}
			cout<<endl;
			return 0;
		}
	}
	map<int, int> dp[1000], prev[1000];
	dp[0][0]=1;
	sort(a, a+n);
	int ans[150010]={};
	for(int i=0; i<n; i++){
		dp[i+1]=dp[i];
		for(auto pr:dp[i]){
			int x=pr.first;
			dp[i+1][x+a[i]]++;
			prev[i+1][x+a[i]]=x;
			dp[i+1][x-a[i]]++;
			prev[i+1][x-a[i]]=x;
			prev[i+1][x]=x;
		}
		if(dp[i+1][0]>1){
			cout<<"Yes"<<endl;
			int k=0;
			for(int j=i+1; j>=1; j--){
				ans[j-1]=k-prev[j][k];
				k-=ans[j-1];
			}
			for(int i=0; i<n; i++) cout<<ans[i]<<" ";
			cout<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}
0