結果

問題 No.1017 Reiwa Sequence
ユーザー kotatsugamekotatsugame
提出日時 2020-04-03 22:29:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,677 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 74,544 KB
実行使用メモリ 16,208 KB
最終ジャッジ日時 2023-09-16 03:15:16
合計ジャッジ時間 12,274 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,564 KB
testcase_01 AC 4 ms
9,504 KB
testcase_02 AC 4 ms
9,488 KB
testcase_03 AC 4 ms
9,484 KB
testcase_04 AC 3 ms
9,560 KB
testcase_05 AC 4 ms
9,496 KB
testcase_06 AC 3 ms
9,504 KB
testcase_07 AC 3 ms
9,664 KB
testcase_08 AC 3 ms
9,540 KB
testcase_09 AC 8 ms
9,576 KB
testcase_10 RE -
testcase_11 AC 14 ms
9,492 KB
testcase_12 RE -
testcase_13 AC 4 ms
10,120 KB
testcase_14 AC 14 ms
9,548 KB
testcase_15 AC 37 ms
9,488 KB
testcase_16 AC 14 ms
9,492 KB
testcase_17 AC 314 ms
9,708 KB
testcase_18 AC 14 ms
9,636 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 4 ms
9,488 KB
testcase_35 AC 3 ms
9,572 KB
testcase_36 AC 3 ms
9,780 KB
testcase_37 AC 3 ms
9,516 KB
testcase_38 AC 3 ms
9,592 KB
testcase_39 AC 3 ms
9,512 KB
testcase_40 AC 47 ms
13,136 KB
testcase_41 AC 47 ms
13,052 KB
testcase_42 AC 45 ms
13,136 KB
testcase_43 AC 46 ms
13,340 KB
testcase_44 AC 47 ms
13,252 KB
testcase_45 AC 47 ms
13,156 KB
testcase_46 AC 46 ms
13,144 KB
testcase_47 AC 45 ms
13,072 KB
testcase_48 AC 80 ms
12,900 KB
testcase_49 AC 72 ms
16,208 KB
testcase_50 AC 60 ms
10,408 KB
testcase_51 AC 3 ms
9,508 KB
testcase_52 RE -
testcase_53 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   10 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int N;
long A[150000];
long B[150000];
vector<int>ids[150001];
pair<int,int>check[300001];
bool vis[300001];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		ids[A[i]].push_back(i);
	}
	if(N<=18)
	{
		for(int I=1;I<1<<N;I++)for(int J=I&I-1;J;J=J-1&I)
		{
			long sum=0;
			for(int k=0;k<N;k++)
			{
				if(I>>k&1)
				{
					if(J>>k&1)B[k]=A[k];
					else B[k]=-A[k];
				}
				else B[k]=0;
				sum+=B[k];
			}
			if(sum==0)
			{
				cout<<"Yes"<<endl;
				for(int k=0;k<N;k++)cout<<B[k]<<(k+1==N?"\n":" ");
				return 0;
			}
		}
		cout<<"No"<<endl;
		return 0;
	}
	vector<pair<int,int> >X;
	for(int i=1;i<=150000;i++)
	{
		if(ids[i].size()==1)
		{
			X.push_back(make_pair(i,ids[i][0]));
		}
		else if(ids[i].size()>=2)
		{
			cout<<"Yes"<<endl;
			for(int k=0;k<N;k++)
			{
				if(ids[i][0]==k)cout<<i;
				else if(ids[i][1]==k)cout<<-i;
				else cout<<0;
				cout<<(k+1==N?"\n":" ");
			}
			return 0;
		}
	}
	for(int i=0;i<X.size();i++)for(int j=i+1;j<X.size();j++)
	{
		int s=X[i].first+X[j].first;
		pair<int,int>q=make_pair(X[i].second,X[j].second);
		if(!vis[s])
		{
			vis[s]=true;
			check[s]=q;
		}
		else
		{
			pair<int,int>p=check[s];
			cout<<"Yes"<<endl;
			for(int k=0;k<N;k++)
			{
				if(p.first==k||p.second==k)cout<<A[k];
				else if(q.first==k||q.second==k)cout<<-A[k];
				else cout<<0;
				cout<<(k+1==N?"\n":" ");
			}
			return 0;
		}
		if(s<=150000&&!ids[s].empty())
		{
			cout<<"Yes"<<endl;
			for(int k=0;k<N;k++)
			{
				if(q.first==k||q.second==k)cout<<A[k];
				else if(A[k]==s)cout<<-A[k];
				else cout<<0;
				cout<<(k+1==N?"\n":" ");
			}
			return 0;
		}
	}
	return 1;
}
0