結果

問題 No.332 数列をプレゼントに
ユーザー kurenaifkurenaif
提出日時 2016-06-11 02:42:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,309 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 91,896 KB
実行使用メモリ 11,812 KB
最終ジャッジ日時 2024-04-17 18:41:20
合計ジャッジ時間 7,518 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 WA -
testcase_02 AC 1 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 19 ms
6,940 KB
testcase_06 AC 17 ms
6,944 KB
testcase_07 WA -
testcase_08 AC 28 ms
6,940 KB
testcase_09 WA -
testcase_10 TLE -
testcase_11 AC 15 ms
6,940 KB
testcase_12 AC 11 ms
6,944 KB
testcase_13 AC 14 ms
6,940 KB
testcase_14 AC 15 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 WA -
testcase_18 AC 49 ms
7,216 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 5 ms
6,940 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 4 ms
6,944 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 15 ms
6,940 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 2 ms
6,940 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 1 ms
6,940 KB
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <limits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <array>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define FOREACH(i, a) for(int i=0;i<a.size();++i)

#define inf 0x3f3f3f3f
#define CLEAR(a) a = decltype(a)()
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define pii pair<int ,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define pi 2*acos(0.0)
#define INFILE() freopen("in.txt","r",stdin)
#define OUTFILE() freopen("out.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14


int main(void) {

	//input 
	ull lim = 1e5;

	ull N, X; cin >> N >> X;
	vector<ull> AO(N);
	vector<ull> AL(N);
	vector<ull> AU(N);

	REP(i, N) {
		cin >> AO[i];
		if (AO[i] < lim)
			AL[i] = AO[i];
		else
			AU[i] = AO[i];
	}

	sort(ALL(AL));
	int upper = -1;

	//GetSum of lower & index of upper.begin
	int sum_lower = 0;
	FOREACH(i, AL) {
		sum_lower += AL[i];
	}

	//dp[value] = (prior value);
	vector<ull> dp(sum_lower+1);
	dp[0] = -1;

	REP(i, AL.size()) {
		RFOR(j, 0, sum_lower + 1) {
		if (j - AL[i] < dp.size())
				if (dp[j] == 0 && dp[j - AL[i]] != 0) dp[j] = AL[i];
		}
	}

	vector<ull> ansvalue;
	for (ull mask = 0; mask < (1 << AU.size()); ++mask) {
		ull sum = 0;
		REP(i, AU.size()) if (mask&(1 << i)) sum += AU[i];
		int s = X - sum;
		if (s >= 0 && s < dp.size()) if (dp[s] != 0){
			REP(i, AU.size()) if (mask&(1 << i)) ansvalue.push_back(AU[i]);
			// retrospective
			while (dp[s] != -1) {
				ansvalue.push_back(dp[s]);
				s = s - dp[s];
			}
			break;
		}
	}

	if (ansvalue.size() == 0) cout << "NO" << endl;
	else
	{
		for (auto &a : AO) {
			auto it = find(ALL(ansvalue), a);
			if (it != ansvalue.end()) {
				ansvalue.erase(it);
				cout << "o";
			}
			else
				cout << "x";
		}
		cout << endl;
	}
	return 0;
}
0