結果
問題 | No.332 数列をプレゼントに |
ユーザー |
![]() |
提出日時 | 2015-12-25 02:24:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 262 ms / 2,000 ms |
コード長 | 1,086 bytes |
コンパイル時間 | 1,567 ms |
コンパイル使用メモリ | 174,728 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 07:30:25 |
合計ジャッジ時間 | 8,604 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 42 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=0;i<n;++i)using namespace std;using ll=long long ;using pii=pair<int,int>;int n;ll x;pii a[110];map<ll,ll> dp[110];void output(string arg){string ans=arg;rep(i,n) ans[a[i].second]=arg[i];cout << ans << endl;return ;}int main(void){cin >> n >> x;const int m=min(n,20);const int offset=n-m;rep(i,n) cin >> a[i].first,a[i].second=i;sort(a,a+n);dp[0][0]=-1LL;rep(i,offset){for(auto &it:dp[i]){ll cur=it.first;dp[i+1][cur]=cur;dp[i+1][cur+a[i].first]=cur;}}rep(mask,1<<m){ll cur=0LL;string ans="";rep(i,m){if(mask&(1<<i)){cur+=a[i+offset].first;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];}assert(cur==0LL);reverse(ans.begin(),ans.end());output(ans);return 0;}}puts("No");return 0;}