結果

問題 No.332 数列をプレゼントに
ユーザー pekempeypekempey
提出日時 2015-12-25 20:32:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 2,024 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 180,008 KB
実行使用メモリ 64,196 KB
最終ジャッジ日時 2023-08-25 21:18:13
合計ジャッジ時間 6,287 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 371 ms
64,196 KB
testcase_06 AC 105 ms
22,480 KB
testcase_07 AC 170 ms
32,928 KB
testcase_08 AC 150 ms
29,424 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 8 ms
5,880 KB
testcase_11 AC 138 ms
29,944 KB
testcase_12 AC 119 ms
25,648 KB
testcase_13 AC 19 ms
8,524 KB
testcase_14 AC 187 ms
36,680 KB
testcase_15 AC 28 ms
10,824 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 13 ms
6,808 KB
testcase_19 AC 65 ms
4,380 KB
testcase_20 AC 20 ms
9,112 KB
testcase_21 AC 38 ms
13,348 KB
testcase_22 AC 23 ms
9,728 KB
testcase_23 AC 44 ms
12,972 KB
testcase_24 AC 48 ms
12,976 KB
testcase_25 AC 44 ms
12,988 KB
testcase_26 AC 45 ms
12,984 KB
testcase_27 AC 46 ms
12,984 KB
testcase_28 AC 21 ms
8,516 KB
testcase_29 AC 20 ms
8,520 KB
testcase_30 AC 21 ms
8,668 KB
testcase_31 AC 19 ms
8,620 KB
testcase_32 AC 21 ms
8,620 KB
testcase_33 AC 17 ms
4,376 KB
testcase_34 AC 65 ms
4,380 KB
testcase_35 AC 259 ms
4,380 KB
testcase_36 AC 1 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,376 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 9 ms
6,104 KB
testcase_44 AC 5 ms
4,788 KB
testcase_45 AC 10 ms
6,432 KB
testcase_46 AC 12 ms
6,660 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;
const int MAX_A = 1e9;

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]);
		}
	}
	assert(y.size() < 28);

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

	dp[0].insert(0);
	pre[0][0] = -1;
	rep (i, m) {
		for (ll 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";
			}
			if (sum >= 1e13) goto loopend;
		}
		mp[sum] = s;
		loopend:;
	}

	for (ll u : dp[m]) {
		if (mp.count(X - u)) {
			string ans;
			ll curr = u;
			int i = m;
			while (i > 0) {
				ll 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