結果
問題 |
No.10 +か×か
|
ユーザー |
|
提出日時 | 2020-01-02 17:57:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 651 bytes |
コンパイル時間 | 1,498 ms |
コンパイル使用メモリ | 170,840 KB |
実行使用メモリ | 8,436 KB |
最終ジャッジ日時 | 2024-11-22 18:13:50 |
合計ジャッジ時間 | 2,118 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 7 WA * 5 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ int n,total; scanf("%d%d",&n,&total); vector<int> a(n); rep(i,n) scanf("%d",&a[i]); static char dp[50][100001]; rep(i,n) rep(x,total+1) dp[i][x]='x'; dp[0][a[0]]='o'; rep(i,n-1){ rep(x,total+1) if(dp[i][x]!='x') if(x*a[i+1]<=total) dp[i+1][x*a[i+1]]='*'; rep(x,total+1) if(dp[i][x]!='x') if(x+a[i+1]<=total) dp[i+1][x+a[i+1]]='+'; } string ans; int res=total; for(int i=n-1;i>0;i--){ char c=dp[i][res]; ans+=c; if(c=='+') res-=a[i]; else res/=a[i]; } reverse(ans.begin(),ans.end()); puts(ans.c_str()); return 0; }