結果

問題 No.1017 Reiwa Sequence
ユーザー satashunsatashun
提出日時 2020-04-03 21:52:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,965 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 203,336 KB
実行使用メモリ 387,092 KB
最終ジャッジ日時 2023-09-16 01:10:39
合計ジャッジ時間 15,658 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
32,148 KB
testcase_01 AC 9 ms
21,840 KB
testcase_02 AC 6 ms
15,768 KB
testcase_03 AC 25 ms
52,632 KB
testcase_04 AC 7 ms
17,804 KB
testcase_05 AC 12 ms
32,344 KB
testcase_06 AC 10 ms
26,080 KB
testcase_07 AC 7 ms
17,804 KB
testcase_08 AC 8 ms
18,008 KB
testcase_09 AC 45 ms
120,208 KB
testcase_10 AC 88 ms
178,120 KB
testcase_11 AC 37 ms
105,956 KB
testcase_12 AC 112 ms
195,236 KB
testcase_13 AC 135 ms
205,928 KB
testcase_14 AC 40 ms
107,916 KB
testcase_15 AC 43 ms
120,088 KB
testcase_16 AC 38 ms
110,048 KB
testcase_17 AC 55 ms
140,888 KB
testcase_18 AC 39 ms
108,000 KB
testcase_19 AC 74 ms
189,716 KB
testcase_20 AC 79 ms
189,972 KB
testcase_21 AC 80 ms
189,724 KB
testcase_22 AC 79 ms
189,772 KB
testcase_23 AC 77 ms
189,708 KB
testcase_24 AC 71 ms
190,016 KB
testcase_25 AC 76 ms
187,672 KB
testcase_26 AC 73 ms
187,676 KB
testcase_27 AC 73 ms
190,092 KB
testcase_28 AC 75 ms
189,960 KB
testcase_29 AC 78 ms
189,836 KB
testcase_30 AC 79 ms
187,800 KB
testcase_31 AC 78 ms
189,916 KB
testcase_32 AC 78 ms
187,772 KB
testcase_33 AC 74 ms
183,704 KB
testcase_34 AC 68 ms
189,836 KB
testcase_35 AC 67 ms
189,960 KB
testcase_36 AC 77 ms
187,868 KB
testcase_37 AC 67 ms
187,992 KB
testcase_38 AC 66 ms
189,820 KB
testcase_39 AC 72 ms
189,912 KB
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 RE -
testcase_45 TLE -
testcase_46 TLE -
testcase_47 TLE -
testcase_48 TLE -
testcase_49 RE -
testcase_50 RE -
testcase_51 AC 8 ms
13,612 KB
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

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 = 15000 * 20 + 5;
const int SZ = B * 2;

bool dp[40][2][SZ];
pii pre[40][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, 40)) {
		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