結果
問題 |
No.332 数列をプレゼントに
|
ユーザー |
![]() |
提出日時 | 2020-06-22 22:01:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 247 ms / 2,000 ms |
コード長 | 2,202 bytes |
コンパイル時間 | 1,471 ms |
コンパイル使用メモリ | 110,520 KB |
実行使用メモリ | 37,572 KB |
最終ジャッジ日時 | 2024-07-03 18:54:23 |
合計ジャッジ時間 | 4,727 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 42 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; int A[100]; int N; ll X; vector<ll> large, small; int th = 100000; set<ll> st, buf; int pre[3000000]; map<ll, vector<int>> idx_map; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N >> X; for(int i = 0; i < N; i++){ cin >> A[i]; if(A[i] >= th) large.push_back(A[i]); else small.push_back(A[i]); idx_map[A[i]].push_back(i); } buf.insert(0); st.insert(0); sort(small.begin(), small.end()); for(int i = 0; i < small.size(); i++){ int m = small[i]; vector<int> v; for(int n : buf){ st.insert(n+m); if(pre[n+m] == 0) pre[n+m] = n; v.push_back(n+m); } for(int n : v){ buf.insert(n); } } int sz = large.size(); for(int i = 0; i < (1<<sz); i++){ ll sum = 0; for(int j = 0; j < sz; j++){ int m = 1<<j; if(i&m){ sum += large[j]; } } if(st.count(X-sum) != 0){ ll cur = X-sum; set<int> used_idx; while(cur != 0){ int d = cur-pre[cur]; // cout << d << ' '; int sz = idx_map[d].size(); used_idx.insert(idx_map[d][sz-1]); idx_map[d].pop_back(); cur = pre[cur]; } for(int j = 0; j < sz; j++){ int m = 1<<j; if(i&m){ int sz = idx_map[large[j]].size(); used_idx.insert(idx_map[large[j]][sz-1]); idx_map[large[j]].pop_back(); } } ll tot = 0; for(int j = 0; j < N; j++){ if(used_idx.count(j) == 0) cout << 'x'; else { tot += A[j]; cout << 'o'; } } cout << endl; return 0; } } cout << "No" << endl; }