結果

問題 No.332 数列をプレゼントに
ユーザー koyumeishikoyumeishi
提出日時 2015-12-25 15:44:15
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,876 bytes
コンパイル時間 1,910 ms
コンパイル使用メモリ 108,072 KB
実行使用メモリ 814,848 KB
最終ジャッジ日時 2023-10-19 03:35:07
合計ジャッジ時間 3,866 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
using namespace std;
template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
template<class T> istream& operator , (istream& is, T& val){ return is >> val;}
template<class T> ostream& operator << (ostream& os, vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"\n":" ");return os;}

int main(){
	long long n,x;
	cin >> n,x;
	vector<long long> a(n);
	cin >> a;

	deque<pair<long long,int>> b(n);
	long long sum = 0;
	for(int i=0; i<n; i++){
		b[i] = {a[i], i};
		sum += a[i];
	}
	sort(b.begin(), b.end());

	int all_size = 14;

	deque<pair<long long,int>> c(n);
	while(b.size() && c.size()<all_size){
		sum -= b.back().first;
		auto tmp = b.back(); b.pop_back();
		c.push_front(tmp);
	}

	vector<long long> dp1((1<<c.size()));
	for(int i=0; i<dp1.size(); i++){
		long long tmp = 0;
		for(int j=0; j<c.size(); j++){
			if((i>>j)&1) tmp += c[j].first;
		}
		dp1[i] = tmp;
	}

	vector<__int128> dp2(sum+1, 0);
	
	for(int i=0; i<b.size(); i++){
		for(__int128 j=sum-b[i].first; j>=0; j--){
			if(dp2[j] == 0 && j != 0) continue;
			dp2[j+b[i].first] = j | (__int128(1)<<b[i].second);
		}
	}
	


	for(int i=0; i<dp1.size(); i++){
		long long rem = x - dp1[i];
		if(rem < 0) continue;

		string ans(n, 'x');
		for(int j=0; j<c.size(); j++){
			if((i>>j)&1) ans[c[j].second] = 'o';
		}

		if(rem == 0){
			cout << ans << endl;
			return 0;
		}
		if(rem <= sum && dp2[rem] != 0){
			for(__int128 j=0; j<b.size(); j++){
				if((dp2[rem]>>j)&1){
					ans[b[j].second] = 'o';
				}
			}
			cout << ans << endl;
			return 0;
		}
	}

	cout << "No" << endl;


	return 0;
}
0