結果

問題 No.1017 Reiwa Sequence
ユーザー 👑 jupirojupiro
提出日時 2020-04-10 21:13:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,061 ms / 2,000 ms
コード長 1,751 bytes
コンパイル時間 1,140 ms
コンパイル使用メモリ 119,448 KB
実行使用メモリ 129,948 KB
最終ジャッジ日時 2023-09-16 07:09:35
合計ジャッジ時間 26,747 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
81,068 KB
testcase_01 AC 40 ms
80,856 KB
testcase_02 AC 33 ms
80,828 KB
testcase_03 AC 33 ms
80,908 KB
testcase_04 AC 33 ms
80,772 KB
testcase_05 AC 33 ms
80,816 KB
testcase_06 AC 33 ms
80,772 KB
testcase_07 AC 33 ms
80,860 KB
testcase_08 AC 33 ms
81,060 KB
testcase_09 AC 34 ms
81,024 KB
testcase_10 AC 165 ms
91,500 KB
testcase_11 AC 35 ms
80,840 KB
testcase_12 AC 1,003 ms
121,912 KB
testcase_13 AC 950 ms
121,792 KB
testcase_14 AC 42 ms
80,952 KB
testcase_15 AC 42 ms
80,856 KB
testcase_16 AC 41 ms
80,808 KB
testcase_17 AC 45 ms
81,340 KB
testcase_18 AC 42 ms
81,004 KB
testcase_19 AC 173 ms
97,196 KB
testcase_20 AC 181 ms
97,168 KB
testcase_21 AC 184 ms
97,168 KB
testcase_22 AC 186 ms
97,124 KB
testcase_23 AC 177 ms
97,236 KB
testcase_24 AC 174 ms
97,324 KB
testcase_25 AC 167 ms
97,212 KB
testcase_26 AC 162 ms
97,272 KB
testcase_27 AC 178 ms
97,172 KB
testcase_28 AC 167 ms
97,112 KB
testcase_29 AC 173 ms
96,960 KB
testcase_30 AC 172 ms
96,912 KB
testcase_31 AC 168 ms
96,124 KB
testcase_32 AC 161 ms
95,268 KB
testcase_33 AC 142 ms
93,064 KB
testcase_34 AC 164 ms
93,068 KB
testcase_35 AC 116 ms
93,100 KB
testcase_36 AC 148 ms
93,092 KB
testcase_37 AC 175 ms
95,148 KB
testcase_38 AC 149 ms
95,140 KB
testcase_39 AC 168 ms
95,076 KB
testcase_40 AC 1,061 ms
128,644 KB
testcase_41 AC 1,013 ms
128,064 KB
testcase_42 AC 1,060 ms
129,948 KB
testcase_43 AC 1,042 ms
128,608 KB
testcase_44 AC 368 ms
102,080 KB
testcase_45 AC 977 ms
126,812 KB
testcase_46 AC 912 ms
126,632 KB
testcase_47 AC 754 ms
123,668 KB
testcase_48 AC 956 ms
121,008 KB
testcase_49 AC 376 ms
100,384 KB
testcase_50 AC 385 ms
103,640 KB
testcase_51 AC 41 ms
80,776 KB
testcase_52 AC 177 ms
97,156 KB
testcase_53 AC 152 ms
97,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

constexpr int mx = 150000 * 22 + 1;
vector<int> dp[mx];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll n; scanf("%lld", &n);
	vector<ll> a(n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	vector<int> res(n);
	if (n > 22) a.resize(22);
	n = a.size();
	for (int S = 0; S < (1 << n); S++) {
		int sum = 0;
		for (int i = 0; i < n; i++) {
			if (S >> i & 1) sum += a[i];
		}
		dp[sum].push_back(S);
	}
	for (int i = 0; i < mx; i++) if (dp[i].size() >= 2) {
		int S1 = dp[i][0];
		int S2 = dp[i][1];
		puts("Yes");
		for (int i = 0; i < n; i++) {
			if (S1 >> i & 1) {
				res[i] = a[i];
			}
			if (S2 >> i & 1) {
				res[i] = -a[i];
			}
		}
		for (int i = 0; i < res.size(); i++) {
			cout << res[i];
			if (i == (int)res.size() - 1) cout << "\n";
			else cout << " ";
		}
		return 0;
	}
	puts("No");
	return 0;
}
0