結果
問題 |
No.332 数列をプレゼントに
|
ユーザー |
![]() |
提出日時 | 2017-02-10 00:16:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,185 bytes |
コンパイル時間 | 1,023 ms |
コンパイル使用メモリ | 102,044 KB |
実行使用メモリ | 196,036 KB |
最終ジャッジ日時 | 2024-12-26 02:36:26 |
合計ジャッジ時間 | 37,684 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 7 WA * 2 RE * 30 TLE * 3 |
ソースコード
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define rrep(i, n) for (int i = (n)-1; i >= 0; i--) using namespace std; typedef long long int lli; vector<lli> rev[1000005]; vector<lli> trev[1000005]; int main() { lli n, x; lli a[105], b[105]; vector<lli> big, small, bigm, smallm; cin >> n >> x; rep(i, n) { cin >> a[i]; if (a[i] > 1e5) { big.push_back(a[i]); bigm.push_back(i); } else { small.push_back(a[i]); smallm.push_back(i); } } bool dp[1000005] = {}; if (small.size() > 0) { dp[small[0]] = true; } for (int i = 1; i < small.size(); i++) { rep(j, 1000005) { if (dp[j]) dp[j + small[i]] = true; } } set<lli> l; rep(j, 1000005) if (dp[j]) l.insert(j); map<lli, lli> memo; set<lli> s; for (int i = 0; i < (1 << big.size()); i++) { int temp = i; lli sum = 0; rep(j, big.size()) { if ((temp >> j) & 1) sum += big[j]; } memo[sum] = i; //cout << sum << endl; s.insert(sum); } s.insert(0); l.insert(0); for (auto j : s) { for (auto i : l) { if (j + i == x) { //cout << i << endl; lli re = memo[j]; bool flag[105] = {}; rep(k, big.size()) { if ((re >> k) & 1) { flag[bigm[k]] = true; } } rev[i].push_back(-1); rep(k, small.size()) { rep(t, 1e6) { trev[t].clear(); for (auto J : rev[t]) trev[t].push_back(J); }; rep(t, 1e6) { if (trev[t].size() > 0) { if (t - small[k] >= 0) { if (rev[t - small[k]].size()) continue; else { rev[t - small[k]].clear(); rev[t - small[k]] = trev[t]; rev[t - small[k]].push_back(k); } } } } } for (auto k : rev[0]) { if (k == -1) continue; // cout << k << endl; flag[smallm[k]] = true; } rep(i, n) { if (flag[i]) cout << "o"; else cout << "x"; } cout << endl; return 0; } } } cout << "No" << endl; }