結果
問題 | No.332 数列をプレゼントに |
ユーザー |
![]() |
提出日時 | 2015-12-25 00:35:20 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 193 ms / 2,000 ms |
コード長 | 1,167 bytes |
コンパイル時間 | 955 ms |
コンパイル使用メモリ | 69,360 KB |
実行使用メモリ | 129,024 KB |
最終ジャッジ日時 | 2024-12-24 07:25:53 |
合計ジャッジ時間 | 9,212 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 42 |
ソースコード
#include <iostream>#include <string>#include <vector>#include <algorithm>#include <bitset>#include <cstdlib>#include <utility>using namespace std;const int lim = 100006;const int sz = lim * 100 + 6;typedef long long LL;typedef bitset<sz> bsz;typedef pair<int,int> pii;typedef pair<LL,int> pli;int n;vector<pii> big, small;vector<bsz> dp;void dfs(int k, int S, LL rest){if(rest < 0){ return; }if(k == (int)big.size()){if(rest >= sz || !dp.back()[rest]){ return; }string ans(n, 'x');for(int i = big.size(); i--; )if(S >> i & 1){ans[big[i].second] = 'o';}for(int p = small.size() - 1; p >= 0; --p){if(!dp[p][rest]){ans[small[p].second] = 'o';rest -= small[p].first;}}cout << ans << '\n';exit(0);}else{dfs(k + 1, S, rest);dfs(k + 1, S | 1 << k, rest - big[k].first);}}int main(){LL x;cin >> n >> x;for(int i = 0; i < n; ++i){int a;cin >> a;(a < lim ? small : big).emplace_back(a, i);}dp.resize(small.size() + 1);dp[0].set(0);for(size_t i = 0; i < small.size(); ++i){dp[i + 1] = dp[i] | dp[i] << small[i].first;}dfs(0, 0, x);cout << "No\n";}