結果

問題 No.332 数列をプレゼントに
ユーザー yosupot
提出日時 2015-12-26 01:46:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 1,594 bytes
コンパイル時間 1,179 ms
コンパイル使用メモリ 105,660 KB
実行使用メモリ 111,872 KB
最終ジャッジ日時 2024-12-24 07:38:12
合計ジャッジ時間 10,199 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

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