結果

問題 No.332 数列をプレゼントに
ユーザー pekempeypekempey
提出日時 2015-12-25 00:38:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 1,938 bytes
コンパイル時間 1,847 ms
コンパイル使用メモリ 179,956 KB
実行使用メモリ 64,252 KB
最終ジャッジ日時 2023-08-25 21:11:02
合計ジャッジ時間 6,047 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 357 ms
64,252 KB
testcase_06 AC 102 ms
22,216 KB
testcase_07 AC 171 ms
32,932 KB
testcase_08 AC 147 ms
29,220 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 9 ms
5,620 KB
testcase_11 AC 142 ms
30,216 KB
testcase_12 AC 118 ms
25,592 KB
testcase_13 AC 20 ms
8,528 KB
testcase_14 AC 187 ms
36,652 KB
testcase_15 AC 28 ms
10,808 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 13 ms
6,764 KB
testcase_19 AC 66 ms
4,376 KB
testcase_20 AC 20 ms
8,988 KB
testcase_21 AC 36 ms
13,336 KB
testcase_22 AC 24 ms
9,700 KB
testcase_23 AC 45 ms
12,960 KB
testcase_24 AC 48 ms
12,932 KB
testcase_25 AC 45 ms
13,100 KB
testcase_26 AC 45 ms
12,968 KB
testcase_27 AC 45 ms
13,032 KB
testcase_28 AC 20 ms
8,640 KB
testcase_29 AC 22 ms
8,720 KB
testcase_30 AC 21 ms
8,560 KB
testcase_31 AC 20 ms
8,768 KB
testcase_32 AC 20 ms
8,556 KB
testcase_33 AC 18 ms
4,380 KB
testcase_34 AC 65 ms
4,380 KB
testcase_35 AC 269 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 3 ms
4,376 KB
testcase_43 AC 9 ms
6,164 KB
testcase_44 AC 5 ms
4,684 KB
testcase_45 AC 10 ms
6,484 KB
testcase_46 AC 11 ms
6,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
using ll = long long;

const int N = 50505;

int main() {
	ll n, X;
	cin >> n >> X;
	vector<ll> a(n);
	rep (i, n) cin >> a[i];

	vector<pair<ll, ll>> ai(n);
	rep (i, n) ai[i] = {a[i], i};
	sort(ai.begin(), ai.end());
	rep (i, n) a[i] = ai[i].first;

	vector<ll> x, y;
	rep (i, n) {
		if (a[i] < N) {
			x.push_back(a[i]);
		} else {
			y.push_back(a[i]);
		}
	}

	int m = x.size();
	vector<set<ll>> dp(m + 1);
	vector<map<ll, int>> pre(m + 1);

	dp[0].insert(0);
	pre[0][0] = -1;
	rep (i, m) {
		for (auto u : dp[i]) {
			if (!dp[i + 1].count(u)) {
				dp[i + 1].insert(u);
				pre[i + 1][u] = u;
			}
			if (!dp[i + 1].count(u + x[i])) {
				dp[i + 1].insert(u + x[i]);
				pre[i + 1][u + x[i]] = u;
			}
		}
	}

	map<ll, string> mp;
	rep (i, 1 << y.size()) {
		ll sum = 0;
		string s;
		rep (j, y.size()) {
			if (i & 1 << j) {
				sum += y[j];
				s += "o";
			} else {
				s += "x";
			}
		}
		mp[sum] = s;
	}

	for (auto u : dp[m]) {
		if (mp.count(X - u)) {
			string ans;
			int curr = u;
			int i = m;
			while (i > 0) {
				int next = pre[i][curr];
				if (next < curr) {
					ans = "o" + ans;
				} else {
					ans = "x" + ans;
				}
				curr = next;
				i--;
			}
			ans += mp[X - u];
			string ans2 = ans;
			rep (i, n) ans2[ai[i].second] = ans[i];
			cout << ans2 << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}
0