結果

問題 No.1017 Reiwa Sequence
ユーザー chocoruskchocorusk
提出日時 2020-04-03 22:42:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,895 bytes
コンパイル時間 969 ms
コンパイル使用メモリ 111,608 KB
実行使用メモリ 32,924 KB
最終ジャッジ日時 2023-09-16 03:44:12
合計ジャッジ時間 13,075 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
32,004 KB
testcase_01 AC 12 ms
32,184 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 12 ms
32,104 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 12 ms
32,300 KB
testcase_06 AC 12 ms
32,004 KB
testcase_07 AC 2 ms
5,388 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 12 ms
32,112 KB
testcase_10 AC 12 ms
32,020 KB
testcase_11 AC 12 ms
32,108 KB
testcase_12 AC 13 ms
32,044 KB
testcase_13 AC 13 ms
32,180 KB
testcase_14 AC 12 ms
32,104 KB
testcase_15 AC 12 ms
32,384 KB
testcase_16 AC 11 ms
32,104 KB
testcase_17 AC 12 ms
32,088 KB
testcase_18 AC 12 ms
32,020 KB
testcase_19 AC 16 ms
32,288 KB
testcase_20 AC 16 ms
32,100 KB
testcase_21 AC 17 ms
32,104 KB
testcase_22 AC 16 ms
32,120 KB
testcase_23 AC 16 ms
32,012 KB
testcase_24 AC 15 ms
32,008 KB
testcase_25 AC 15 ms
32,012 KB
testcase_26 AC 15 ms
32,048 KB
testcase_27 AC 12 ms
32,096 KB
testcase_28 AC 15 ms
32,048 KB
testcase_29 AC 13 ms
32,292 KB
testcase_30 AC 12 ms
32,060 KB
testcase_31 AC 12 ms
32,104 KB
testcase_32 AC 12 ms
32,032 KB
testcase_33 AC 13 ms
32,036 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
5,492 KB
testcase_37 AC 11 ms
32,328 KB
testcase_38 AC 12 ms
32,340 KB
testcase_39 AC 12 ms
32,036 KB
testcase_40 AC 67 ms
32,560 KB
testcase_41 AC 68 ms
32,412 KB
testcase_42 AC 65 ms
32,924 KB
testcase_43 AC 68 ms
32,360 KB
testcase_44 AC 68 ms
32,412 KB
testcase_45 AC 66 ms
32,444 KB
testcase_46 AC 66 ms
32,392 KB
testcase_47 AC 67 ms
32,396 KB
testcase_48 AC 15 ms
4,376 KB
testcase_49 AC 87 ms
32,616 KB
testcase_50 AC 16 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 13 ms
32,064 KB
testcase_53 AC 13 ms
32,080 KB
権限があれば一括ダウンロードができます

ソースコード

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 m=min(n, 35);
	ll s1[1<<18]={}, s2[1<<18]={};
	for(int i=0; i<(1<<(m/2)); i++){
		for(int j=0; j<m/2; j++){
			if(i&(1<<j)) s1[i]+=a[j];
		}
	}
	for(int i=0; i<(1<<(m-m/2)); i++){
		for(int j=0; j<m-m/2; j++){
			if(i&(1<<j)) s2[i]+=a[j+m/2];
		}
	}
	int ans[150010]={};
	P s[3000000];
	fill(s, s+3000000, P(-1, -1));
	for(int i=0; i<(1<<(m/2)); i++){
		for(int j=0; j<(1<<(m-m/2)); j++){
			if(s[s1[i]+s2[j]]==P(-1, -1)){
				s[s1[i]+s2[j]]=P(i, j);
			}else{
				cout<<"Yes"<<endl;
				int i1=s[s1[i]+s2[j]].first, j1=s[s1[i]+s2[j]].second;
				for(int k=0; k<m/2; k++){
					if(i&(1<<k)){
						ans[k]+=a[k];
					}
					if(i1&(1<<k)) ans[k]-=a[k];
				}
				for(int k=0; k<m-m/2; k++){
					if(j&(1<<k)){
						ans[k+m/2]+=a[k+m/2];
					}
					if(j1&(1<<k)) ans[k+m/2]-=a[k+m/2];
				}
				for(int k=0; k<n; k++) cout<<ans[k]<<" ";
				cout<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}
0