結果

問題 No.1017 Reiwa Sequence
ユーザー 00 Sakuda
提出日時 2024-04-01 02:16:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,102 bytes
コンパイル時間 2,013 ms
コンパイル使用メモリ 198,476 KB
最終ジャッジ日時 2025-02-20 18:39:16
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace atcoder;
using namespace std;
using ll = long long;
ll INF = (1LL << 60);
bool ret = false;
vector<ll> solve(vector<ll> A) {
	int N = A.size();
	vector<int> IS((1 << 22) + 1, -1);
	vector<ll> ans = A;
	for (int bit = 0;bit < (1 << N);bit++) {
		ll s = 0;
		for (int i = 0;i < N;i++) s += (bit & (1 << i) ? 1 : 0) * A[i];
		if (IS[s] == -1) {
			IS[s] = bit;
			continue;
		}
		int type = IS[s];
		ret = true;
		for (int i = 0;i < N;i++) {
			bool t1 = bit & (1 << i);
			bool t2 = type & (1 << i);
			if (t1 and t2) {
				ans[i] = 0;
			} else if (t1) {
				
			} else if (t2) {
				ans[i] *= -1;
			} else {
				ans[i] = 0;
			}
		}
		break;
	}
	return ans;
}
int main() {
	int N;cin >> N;
	vector<ll> A(N);
	vector<ll> B, C;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		if (i < 22) {
			B.push_back(A[i]);
		} else {
			C.push_back(0);
		}
	}
	vector<ll> D = solve(B);
	if (!ret) {
		cout << "No" << endl;return 0;
	}
	cout << "Yes" << endl;
	for (auto v : D) cout << v << " ";
	for (auto v : C) cout << v << " ";
	cout << endl;
}
0