結果
問題 | No.332 数列をプレゼントに |
ユーザー |
|
提出日時 | 2017-01-05 19:19:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 484 ms / 2,000 ms |
コード長 | 1,500 bytes |
コンパイル時間 | 1,099 ms |
コンパイル使用メモリ | 99,380 KB |
実行使用メモリ | 80,840 KB |
最終ジャッジ日時 | 2024-12-24 09:02:34 |
合計ジャッジ時間 | 5,496 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 42 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <numeric>#include <unordered_map>#include <functional>#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)typedef long long ll;using namespace std;int main() {int n; ll x; cin >> n >> x;vector<ll> a(n); repeat (i,n) cin >> a[i];vector<int> rank(n); whole(iota, rank, 0);whole(sort, rank, [&](int i, int j) { return a[i] < a[j]; });const ll limit = 1e5;unordered_map<int,vector<int> > low;low[0] = vector<int>();int i = 0;for (; i < n and a[rank[i]] < limit; ++ i) {unordered_map<int,vector<int> > prv = low;for (auto & it : prv) {it.second.push_back(rank[i]);low[it.first + a[rank[i]]] = it.second;}}vector<int> high; ll acc = 0;function<bool (int)> dfs = [&](int i) {if (i >= n) return false;if (dfs(i+1)) return true;acc += a[rank[i]];high.push_back(rank[i]);if (low.count(x - acc)) return true;if (dfs(i+1)) return true;high.pop_back();acc -= a[rank[i]];return false;};if (low.count(x) or dfs(i)) {string ans(n, 'x');for (int j : low[x - acc]) ans[j] = 'o';for (int j : high) ans[j] = 'o';cout << ans << endl;} else {cout << "No" << endl;}return 0;}