結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 371 ms
64,236 KB
testcase_06 AC 101 ms
22,280 KB
testcase_07 AC 169 ms
32,940 KB
testcase_08 AC 150 ms
29,264 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 9 ms
5,596 KB
testcase_11 AC 140 ms
29,872 KB
testcase_12 AC 119 ms
25,860 KB
testcase_13 AC 19 ms
8,620 KB
testcase_14 AC 186 ms
36,624 KB
testcase_15 AC 28 ms
10,852 KB
testcase_16 AC 6 ms
4,384 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 13 ms
6,780 KB
testcase_19 AC 68 ms
4,384 KB
testcase_20 AC 21 ms
9,112 KB
testcase_21 AC 36 ms
13,292 KB
testcase_22 AC 23 ms
9,612 KB
testcase_23 AC 44 ms
12,860 KB
testcase_24 AC 46 ms
12,984 KB
testcase_25 AC 45 ms
12,776 KB
testcase_26 AC 45 ms
12,992 KB
testcase_27 AC 44 ms
12,776 KB
testcase_28 AC 21 ms
8,380 KB
testcase_29 AC 20 ms
8,344 KB
testcase_30 AC 20 ms
8,480 KB
testcase_31 AC 21 ms
8,308 KB
testcase_32 AC 21 ms
8,324 KB
testcase_33 AC 18 ms
4,380 KB
testcase_34 AC 68 ms
4,380 KB
testcase_35 AC 274 ms
4,380 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 3 ms
4,384 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 3 ms
4,380 KB
testcase_40 AC 3 ms
4,384 KB
testcase_41 AC 3 ms
4,384 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 10 ms
6,116 KB
testcase_44 AC 5 ms
4,748 KB
testcase_45 AC 11 ms
6,424 KB
testcase_46 AC 12 ms
6,708 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]);
		}
	}

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

	dp[0].insert(0);
	pre[0][0] = 0;
	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) {
				if (y[j] > X) goto loopend;
				sum += y[j];
				s += "o";
			} else {
				s += "x";
			}
		}
		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