結果
問題 | No.10 +か×か |
ユーザー |
|
提出日時 | 2014-10-05 18:19:12 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 807 ms / 5,000 ms |
コード長 | 1,137 bytes |
コンパイル時間 | 472 ms |
コンパイル使用メモリ | 57,796 KB |
実行使用メモリ | 468,224 KB |
最終ジャッジ日時 | 2024-12-14 15:25:08 |
合計ジャッジ時間 | 5,837 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#include <stdlib.h> #include <iostream> #include <string> using namespace std; #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) bool dp1[101][100010]; string dp2[101][100010]; int main(){ int N, total, A; cin >> N >> total; REP(i,N+1) REP(j,total+1) dp1[i][j] = false; cin >> A; dp1[0][A] = true; REP(i,N-1){ cin >> A; for(int j = 0; j <= total; j++){ if(!dp1[i][j]) continue; int k = j + A; if(k <= total){ string ks = dp2[i][j] + "0"; dp1[i+1][k] = true; if(dp2[i+1][k] == "" || dp2[i+1][k] > ks) dp2[i+1][k] = ks; } int l = j * A; if(l <= total){ string ls = dp2[i][j] + "1"; dp1[i+1][l] = true; if(dp2[i+1][l] == "" || dp2[i+1][l] > ls) dp2[i+1][l] = ls; } } } string res = dp2[N-1][total]; if(res != ""){ REP(i,res.size()){ if(res[i] == '0') res[i] = '+'; if(res[i] == '1') res[i] = '*'; } cout << res << endl; } return 0; }