結果

問題 No.1017 Reiwa Sequence
ユーザー satashunsatashun
提出日時 2020-04-03 21:58:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,966 bytes
コンパイル時間 2,146 ms
コンパイル使用メモリ 201,736 KB
実行使用メモリ 662,240 KB
最終ジャッジ日時 2023-09-16 01:32:43
合計ジャッジ時間 28,796 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
46,364 KB
testcase_01 AC 29 ms
29,936 KB
testcase_02 AC 20 ms
21,916 KB
testcase_03 AC 85 ms
79,136 KB
testcase_04 AC 20 ms
21,792 KB
testcase_05 AC 41 ms
46,492 KB
testcase_06 AC 31 ms
38,372 KB
testcase_07 AC 20 ms
22,020 KB
testcase_08 AC 20 ms
21,924 KB
testcase_09 AC 141 ms
174,400 KB
testcase_10 AC 283 ms
316,536 KB
testcase_11 AC 122 ms
193,820 KB
testcase_12 MLE -
testcase_13 MLE -
testcase_14 AC 120 ms
171,164 KB
testcase_15 AC 135 ms
201,952 KB
testcase_16 AC 125 ms
202,188 KB
testcase_17 AC 185 ms
258,496 KB
testcase_18 AC 121 ms
187,684 KB
testcase_19 MLE -
testcase_20 AC 308 ms
406,388 KB
testcase_21 MLE -
testcase_22 AC 312 ms
448,160 KB
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
testcase_26 MLE -
testcase_27 MLE -
testcase_28 MLE -
testcase_29 AC 311 ms
452,672 KB
testcase_30 MLE -
testcase_31 AC 295 ms
446,800 KB
testcase_32 AC 284 ms
445,728 KB
testcase_33 AC 249 ms
359,276 KB
testcase_34 MLE -
testcase_35 MLE -
testcase_36 MLE -
testcase_37 AC 268 ms
456,244 KB
testcase_38 MLE -
testcase_39 AC 288 ms
457,816 KB
testcase_40 MLE -
testcase_41 MLE -
testcase_42 MLE -
testcase_43 MLE -
testcase_44 MLE -
testcase_45 MLE -
testcase_46 MLE -
testcase_47 MLE -
testcase_48 AC 401 ms
428,432 KB
testcase_49 AC 262 ms
194,828 KB
testcase_50 MLE -
testcase_51 AC 12 ms
15,584 KB
testcase_52 MLE -
testcase_53 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int B = 150000 * 11 + 5;
const int SZ = B * 2;

bool dp[24][2][SZ];
pii pre[24][2][SZ];

int main() {
	dp[0][0][B] = 1;
	int N; cin >> N;
	V<int> A(N), ans(N);
	rep(i, N) {
		cin >> A[i];
	}
	int now = 0;
	rep(i, min(N, 23)) {
		rep(k, 2) {
			rep(j, SZ) {
				if (dp[i][k][j]) {
					if (j + A[i] < SZ) {
						dp[i+1][1][j + A[i]] = 1;
						pre[i+1][1][j + A[i]] = mp(k, j);
					}
					dp[i+1][k][j] = 1;
					pre[i+1][k][j] = mp(k, j);
					if (j - A[i] >= 0) {
						dp[i+1][1][j - A[i]] = 1;
						pre[i+1][1][j - A[i]] = mp(k, j);
					}					
				}
			}
		}
		now++;
	}

	if (!dp[now][1][B]) {
		puts("No");
		return 0;
	}

	int p = now, k = 1, v = B;
	rep(t, now) {
		pii nx = pre[p][k][v];
		--p;
		if (nx.se < v) {
			ans[p] = 1;
		} else if (nx.se > v) {
			ans[p] = -1;
		} else {
			ans[p] = 0;
		}
		tie(k, v) = nx;
	}

	puts("Yes");
	rep(i, N) {
		printf("%d%c", ans[i] * A[i], i == N-1 ? '\n' : ' ');
	}

	return 0;
}
0