結果

問題 No.332 数列をプレゼントに
ユーザー yosupotyosupot
提出日時 2015-12-26 01:46:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 1,594 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 103,684 KB
実行使用メモリ 113,128 KB
最終ジャッジ日時 2023-08-25 21:20:15
合計ジャッジ時間 8,010 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
8,384 KB
testcase_01 AC 7 ms
8,420 KB
testcase_02 AC 4 ms
6,324 KB
testcase_03 AC 4 ms
6,336 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 78 ms
57,648 KB
testcase_06 AC 96 ms
71,692 KB
testcase_07 AC 129 ms
95,732 KB
testcase_08 AC 97 ms
73,976 KB
testcase_09 AC 11 ms
10,704 KB
testcase_10 AC 20 ms
14,520 KB
testcase_11 AC 74 ms
55,620 KB
testcase_12 AC 135 ms
100,628 KB
testcase_13 AC 104 ms
80,120 KB
testcase_14 AC 52 ms
41,160 KB
testcase_15 AC 122 ms
96,448 KB
testcase_16 AC 110 ms
84,168 KB
testcase_17 AC 127 ms
98,620 KB
testcase_18 AC 97 ms
73,928 KB
testcase_19 AC 107 ms
82,116 KB
testcase_20 AC 125 ms
94,444 KB
testcase_21 AC 134 ms
102,632 KB
testcase_22 AC 119 ms
90,572 KB
testcase_23 AC 131 ms
98,528 KB
testcase_24 AC 131 ms
98,496 KB
testcase_25 AC 130 ms
98,488 KB
testcase_26 AC 130 ms
98,552 KB
testcase_27 AC 131 ms
98,500 KB
testcase_28 AC 130 ms
98,756 KB
testcase_29 AC 131 ms
98,492 KB
testcase_30 AC 132 ms
98,580 KB
testcase_31 AC 130 ms
98,564 KB
testcase_32 AC 131 ms
98,544 KB
testcase_33 AC 127 ms
96,580 KB
testcase_34 AC 136 ms
92,408 KB
testcase_35 AC 182 ms
90,352 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 136 ms
102,648 KB
testcase_38 AC 135 ms
102,588 KB
testcase_39 AC 136 ms
102,604 KB
testcase_40 AC 147 ms
112,868 KB
testcase_41 AC 150 ms
113,128 KB
testcase_42 AC 150 ms
112,876 KB
testcase_43 AC 151 ms
112,828 KB
testcase_44 AC 151 ms
112,960 KB
testcase_45 AC 148 ms
110,860 KB
testcase_46 AC 66 ms
51,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;

using P = pair<ll, ll>;

ll x;
vector<P> big;
vector<P> small;
const int MN = 110;
const int B = 10100;

void solve() {
	int n = small.size();
	static bool dp[MN][B*MN] = {};
	dp[0][0] = true;
	for (int i = 1; i <= n; i++) {
		int d = small[i-1].first;
		for (int j = 0; j < B*MN; j++) {
			dp[i][j] = dp[i-1][j];
			if (j >= d) {
				dp[i][j] |= dp[i-1][j-d];
			}
		}
	}

	int m = (int)big.size();

	for (int i = 0; i < (1<<m); i++) {
		ll sm = x;
		for (int j = 0; j < m; j++) {
			if ((i>>j) & 1) {
				sm -= big[j].first;
			}
		}
		if (0 <= sm && sm < MN*B && dp[n][sm]) {
			static bool res[MN];
			for (int j = 0; j < m; j++) {
				if ((i>>j) & 1) {
					res[big[j].second] = true;
				}
			}
			for (int j = n; j >= 1; j--) {
				if (dp[j-1][sm]) {
					continue;
				}
				sm -= small[j-1].first;
				res[small[j-1].second] = true;
			}

			string s = "";

			for (int j = 0; j < n+m; j++) {
				if (res[j]) {
					s += 'o';
				} else {
					s += 'x';
				}
			}

			cout << s << endl;
			return;
		}
	}
	cout << "No" << endl;
}


int main() {
	int n;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a < B) {
			small.push_back(P(a, i));
		} else {
			big.push_back(P(a, i));
		}
	}

	solve();
    return 0;
}
0