結果

問題 No.332 数列をプレゼントに
ユーザー yumakmcyumakmc
提出日時 2016-02-23 20:19:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 1,669 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 172,840 KB
実行使用メモリ 158,764 KB
最終ジャッジ日時 2023-08-25 21:51:51
合計ジャッジ時間 10,057 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 269 ms
82,568 KB
testcase_06 AC 197 ms
95,608 KB
testcase_07 AC 211 ms
94,992 KB
testcase_08 AC 242 ms
120,564 KB
testcase_09 AC 13 ms
7,072 KB
testcase_10 AC 187 ms
54,804 KB
testcase_11 AC 198 ms
84,432 KB
testcase_12 AC 300 ms
141,540 KB
testcase_13 AC 200 ms
90,640 KB
testcase_14 AC 131 ms
53,552 KB
testcase_15 AC 22 ms
7,248 KB
testcase_16 AC 5 ms
4,752 KB
testcase_17 AC 6 ms
4,672 KB
testcase_18 AC 11 ms
5,860 KB
testcase_19 AC 8 ms
5,112 KB
testcase_20 AC 16 ms
6,700 KB
testcase_21 AC 28 ms
8,512 KB
testcase_22 AC 18 ms
6,788 KB
testcase_23 AC 335 ms
156,560 KB
testcase_24 AC 343 ms
156,760 KB
testcase_25 AC 335 ms
156,736 KB
testcase_26 AC 333 ms
156,692 KB
testcase_27 AC 339 ms
156,604 KB
testcase_28 AC 352 ms
158,720 KB
testcase_29 AC 351 ms
158,748 KB
testcase_30 AC 348 ms
158,560 KB
testcase_31 AC 354 ms
158,560 KB
testcase_32 AC 347 ms
158,764 KB
testcase_33 AC 8 ms
5,292 KB
testcase_34 AC 9 ms
5,552 KB
testcase_35 AC 11 ms
5,904 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 5 ms
4,380 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 5 ms
4,384 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 8 ms
4,556 KB
testcase_44 AC 5 ms
4,380 KB
testcase_45 AC 16 ms
9,724 KB
testcase_46 AC 14 ms
7,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;

void cou(vector<int>bs) {
	for (int i = 0; i < bs.size(); ++i) {
		if (bs[i]) {
			cout << 'o';
		}
		else {
			cout << 'x';
		}
	}
	cout << endl;
}

vector<pair<long long int,int>>as;
int main() {
	long long int N, X; cin >> N >> X;
	as.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> as[i].first;
		as[i].second = i;
	}
	sort(as.begin(),as.end());
	unordered_map<long long int,vector<int>>premap;
	premap[0] = vector<int>(N);
	int now = 0;
	while (premap.size() < 100000&&now!=N) {
		unordered_map<long long int , vector<int>>newmap(premap);
		for (auto i : premap) {
			i.second[as[now].second]=(true);
			newmap[i.first+as[now].first] =i.second;
		}
		premap = newmap;
		now++;
	}
	if (now == N) {
		auto ansit = premap.find(X);
		if (ansit != premap.end()) {
			cou(ansit->second);
		}
		else {
			cout << "No" << endl;
		}
		return 0;
	}
	else {
		map<long long int, vector<int>>lastmap;
		lastmap[0]=vector<int>(N);
		while (now != N) {
			map<long long int, vector<int>>newmap(lastmap);	
			for (auto i : lastmap) {
				i.second[as[now].second] = (true);
				newmap[i.first + as[now].first] = i.second;
			}
			lastmap = newmap;
			now++;
		}
		for (const auto& p : premap) {
			auto ansit = lastmap.find(X-p.first);
			if (ansit != lastmap.end()) {
				vector<int>ansbs(p.second);
				for (int i = 0; i < N; ++i) {
					ansbs[i] = ansbs[i] || ansit->second[i];
				}
				cou(ansbs);
				return 0;
			}
		}
		cout << "No" << endl;
		return 0;
	}
	return 0;
}
0