結果

問題 No.1017 Reiwa Sequence
ユーザー HIR180HIR180
提出日時 2020-04-03 21:48:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 2,832 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 197,080 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2023-09-16 01:02:30
合計ジャッジ時間 14,468 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,816 KB
testcase_01 AC 5 ms
8,756 KB
testcase_02 AC 4 ms
8,816 KB
testcase_03 AC 6 ms
8,704 KB
testcase_04 AC 4 ms
8,632 KB
testcase_05 AC 5 ms
12,800 KB
testcase_06 AC 5 ms
10,652 KB
testcase_07 AC 4 ms
8,696 KB
testcase_08 AC 4 ms
8,804 KB
testcase_09 AC 12 ms
18,844 KB
testcase_10 AC 10 ms
16,772 KB
testcase_11 AC 10 ms
19,080 KB
testcase_12 AC 18 ms
20,132 KB
testcase_13 AC 13 ms
19,268 KB
testcase_14 AC 11 ms
18,940 KB
testcase_15 AC 14 ms
18,936 KB
testcase_16 AC 12 ms
19,744 KB
testcase_17 AC 22 ms
20,988 KB
testcase_18 AC 12 ms
19,300 KB
testcase_19 AC 29 ms
20,876 KB
testcase_20 AC 29 ms
20,880 KB
testcase_21 AC 29 ms
20,984 KB
testcase_22 AC 31 ms
20,980 KB
testcase_23 AC 29 ms
21,036 KB
testcase_24 AC 30 ms
21,080 KB
testcase_25 AC 29 ms
20,972 KB
testcase_26 AC 28 ms
21,036 KB
testcase_27 AC 29 ms
20,880 KB
testcase_28 AC 30 ms
20,880 KB
testcase_29 AC 29 ms
20,856 KB
testcase_30 AC 30 ms
20,976 KB
testcase_31 AC 20 ms
20,992 KB
testcase_32 AC 25 ms
21,036 KB
testcase_33 AC 9 ms
18,820 KB
testcase_34 AC 21 ms
20,876 KB
testcase_35 AC 21 ms
20,900 KB
testcase_36 AC 18 ms
20,848 KB
testcase_37 AC 25 ms
20,840 KB
testcase_38 AC 22 ms
20,988 KB
testcase_39 AC 26 ms
20,856 KB
testcase_40 AC 26 ms
20,020 KB
testcase_41 AC 31 ms
21,312 KB
testcase_42 AC 30 ms
21,560 KB
testcase_43 AC 28 ms
20,740 KB
testcase_44 AC 33 ms
21,120 KB
testcase_45 AC 30 ms
21,176 KB
testcase_46 AC 34 ms
21,792 KB
testcase_47 AC 31 ms
21,524 KB
testcase_48 AC 41 ms
22,400 KB
testcase_49 AC 43 ms
21,888 KB
testcase_50 AC 32 ms
13,312 KB
testcase_51 AC 4 ms
10,732 KB
testcase_52 AC 28 ms
20,876 KB
testcase_53 AC 28 ms
20,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Let's join Kaede Takagaki Fan Club !!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
#define SZ 1000000
bitset<SZ*2+5>cur, nxt, nxt2;
int n,a[150005],aa[150005],cr[150005];
P fr[SZ*2+5];
int main(){
	ios::sync_with_stdio(false);
	g(n);
	repn(i,n) g(aa[i]);
	vector<P>vec;
	repn(i,n) vec.pb(mp(aa[i], i));
	mt19937 mt(614);
	shuffle(vec.begin(), vec.end(), mt);
	repn(i,n){
		a[i] = vec[i-1].fi;
		cr[i] = vec[i-1].sc;
	}
	
	cur[SZ] = 1;
	fr[SZ] = mp(0, 0);
	auto output=[&](vector<P>vi){
		vector<int>ans(n+1);
		repn(i,n) ans[i] = 0;
		rep(i,vi.size()) ans[cr[vi[i].fi]] = a[vi[i].fi] * vi[i].sc;
		repn(i,n) o(ans[i], 1);
		cout<<'\n';
		return;
	};
	repn(i,n){
	     //cout << i << endl;
		if(cur[SZ-a[i]]){ //cout << i << endl;
			vector<P>ans;
			ans.pb(mp(i, 1));
			int cur = SZ-a[i];
			//cout << fr[cur].fi << " " << fr[cur].sc << endl;
			while(cur != SZ){
				P k = fr[cur];
				ans.pb(mp(k.fi, k.sc));
				cur -= k.sc * a[k.fi];
			}
			o("Yes");
			output(ans);
			return 0;
		}
		if(cur[SZ+a[i]]){
			vector<P>ans;
			ans.pb(mp(a[i], -1));
			int cur = SZ+a[i];
			while(cur != SZ){
				P k = fr[cur];
				ans.pb(mp(k.fi, k.sc));
				cur -= k.sc * a[k.fi];
			}
			o("Yes");
			output(ans);
			return 0;
		}
		
		nxt = cur | (cur << a[i]);
		nxt ^= cur;
		for(int ii=nxt._Find_first();ii< nxt.size();ii = nxt._Find_next(ii)){
			fr[ii]  = mp(i, 1); //cout << ii << " " << i << " " << 1 << endl;
		}
		nxt ^= cur;
		nxt2 = nxt | (cur >> a[i]);
		nxt2 ^= nxt;
		for(int ii=nxt2._Find_first();ii<nxt2.size();ii = nxt2._Find_next(ii)){
			fr[ii]  = mp(i, -1); //cout << ii << " " << i << " " << -1 << endl;
		}
		cur = nxt2^nxt;
	}
	o("No");
}
0