結果

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

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
int N,K;
int a[110];
vector <pair <int, int> > v; // a[i], id
bitset <8000010> dp[90];
bool found = false;
bool ans[110];
bool ans2[110];
void check(ll X){
int i;
if(X < 0 || X >= 8000010 || found) return;
if(!dp[N-K][X]) return;
found = true;
for(i=N-K-1;i>=0;i--){
int id = v[i].second;
if(a[id] <= X && dp[i][X-a[id]]){
ans[id] = true;
X -= a[id];
} else {
ans[id] = false;
}
}
REP(i,N) ans2[i] = ans[i];
}
void dfs(int pos, ll X){
if(pos == N-K){
check(X);
return;
}
int id = v[pos-1].second;
ans[id] = false;
dfs(pos-1, X);
ans[id] = true;
dfs(pos-1, X-a[id]);
}
int main(void){
int i;
ll X;
cin >> N >> X;
REP(i,N) cin >> a[i];
REP(i,N) v.push_back(make_pair(a[i], i));
sort(v.begin(),v.end());
K = min(N, 20);
dp[0].reset();
dp[0][0] = true;
REP(i,N-K) dp[i+1] = ((dp[i] << a[v[i].second]) | dp[i]);
dfs(N, X);
if(!found){
cout << "No" << endl;
} else {
string s;
REP(i,N) s += (ans2[i] ? 'o' : 'x');
cout << s << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0