結果
問題 |
No.332 数列をプレゼントに
|
ユーザー |
![]() |
提出日時 | 2015-12-25 02:00:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 898 bytes |
コンパイル時間 | 1,916 ms |
コンパイル使用メモリ | 172,124 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-09-18 23:40:16 |
合計ジャッジ時間 | 5,679 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | WA * 2 TLE * 1 -- * 39 |
ソースコード
#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,25); 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; }