結果

問題 No.1017 Reiwa Sequence
ユーザー HIR180HIR180
提出日時 2020-04-03 21:46:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,638 bytes
コンパイル時間 3,353 ms
コンパイル使用メモリ 196,540 KB
実行使用メモリ 20,884 KB
最終ジャッジ日時 2024-07-03 02:00:30
合計ジャッジ時間 33,327 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 6 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 10 ms
13,312 KB
testcase_10 AC 13 ms
16,768 KB
testcase_11 AC 10 ms
16,000 KB
testcase_12 AC 13 ms
17,664 KB
testcase_13 AC 9 ms
13,568 KB
testcase_14 AC 11 ms
12,928 KB
testcase_15 AC 12 ms
16,256 KB
testcase_16 AC 12 ms
17,792 KB
testcase_17 AC 21 ms
20,224 KB
testcase_18 AC 12 ms
16,768 KB
testcase_19 AC 26 ms
20,264 KB
testcase_20 AC 26 ms
20,388 KB
testcase_21 AC 26 ms
20,480 KB
testcase_22 AC 29 ms
20,224 KB
testcase_23 AC 25 ms
20,352 KB
testcase_24 AC 27 ms
20,224 KB
testcase_25 AC 27 ms
20,352 KB
testcase_26 AC 26 ms
20,352 KB
testcase_27 AC 25 ms
20,352 KB
testcase_28 AC 27 ms
20,264 KB
testcase_29 AC 15 ms
20,352 KB
testcase_30 AC 20 ms
20,224 KB
testcase_31 AC 23 ms
20,224 KB
testcase_32 AC 26 ms
20,392 KB
testcase_33 AC 12 ms
14,208 KB
testcase_34 AC 23 ms
20,224 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 7 ms
7,168 KB
testcase_37 AC 25 ms
20,352 KB
testcase_38 AC 4 ms
5,376 KB
testcase_39 AC 25 ms
20,352 KB
testcase_40 AC 38 ms
20,772 KB
testcase_41 AC 39 ms
20,864 KB
testcase_42 AC 41 ms
20,760 KB
testcase_43 AC 40 ms
20,756 KB
testcase_44 AC 19 ms
5,376 KB
testcase_45 AC 40 ms
20,752 KB
testcase_46 AC 38 ms
20,884 KB
testcase_47 AC 37 ms
20,864 KB
testcase_48 AC 35 ms
14,464 KB
testcase_49 AC 25 ms
5,760 KB
testcase_50 AC 25 ms
5,760 KB
testcase_51 AC 3 ms
5,376 KB
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
P fr[SZ*2+5];
int main(){
	ios::sync_with_stdio(false);
	g(n); repn(i,n) g(a[i]);
	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[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