結果
問題 |
No.332 数列をプレゼントに
|
ユーザー |
![]() |
提出日時 | 2015-12-25 02:01:13 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 899 bytes |
コンパイル時間 | 1,751 ms |
コンパイル使用メモリ | 172,792 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-18 23:41:24 |
合計ジャッジ時間 | 16,744 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 22 WA * 20 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) using namespace std; using ll=long long ; int n; ll x,a[110]; map<ll,ll> dp[110]; int main(void){ cin >> n >> x; const int m=min(n,21); const int offset=n-m; rep(i,n) cin >> a[i]; sort(a,a+n); dp[0][0]=0LL; rep(i,offset){ for(auto &it:dp[i]){ ll cur=it.first; dp[i+1][cur]=cur; dp[i+1][cur+a[i]]=cur; } } rep(mask,1<<m){ ll cur=0LL; string ans=""; rep(i,m){ if(mask&(1<<i)){ cur+=a[i+offset]; ans+="o"; }else{ ans+="x"; } } if(x<cur) continue; cur=x-cur; if(dp[offset].find(cur)!=dp[offset].end()){ reverse(ans.begin(),ans.end()); for(int i=offset;i>0;--i){ if(cur!=dp[i][cur]){ ans+="o"; }else{ ans+="x"; } cur=dp[i][cur]; } reverse(ans.begin(),ans.end()); cout << ans << endl; return 0; } } puts("No"); return 0; }