結果
問題 | No.10 +か×か |
ユーザー | mayoko_ |
提出日時 | 2014-12-11 17:37:34 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 602 ms / 5,000 ms |
コード長 | 1,229 bytes |
コンパイル時間 | 563 ms |
コンパイル使用メモリ | 75,696 KB |
実行使用メモリ | 353,896 KB |
最終ジャッジ日時 | 2023-08-21 06:09:27 |
合計ジャッジ時間 | 3,537 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
203,476 KB |
testcase_01 | AC | 73 ms
203,484 KB |
testcase_02 | AC | 73 ms
203,472 KB |
testcase_03 | AC | 602 ms
353,896 KB |
testcase_04 | AC | 90 ms
205,312 KB |
testcase_05 | AC | 73 ms
203,556 KB |
testcase_06 | AC | 595 ms
352,528 KB |
testcase_07 | AC | 260 ms
252,252 KB |
testcase_08 | AC | 111 ms
211,760 KB |
testcase_09 | AC | 101 ms
208,372 KB |
testcase_10 | AC | 73 ms
203,436 KB |
testcase_11 | AC | 73 ms
203,616 KB |
ソースコード
#include <sstream> #include <string> #include <vector> #include <map> #include <algorithm> #include <iostream> #include <utility> #include <set> #include <cctype> #include <queue> #include <stack> #include <cstdio> #include <cstdlib> #include <cmath> #define INF 1000000000 using namespace std; typedef long long ll; const int MAXN = 64; string dp[MAXN][100100]; int a[MAXN]; int main(void) { int N, Total; cin >> N; cin >> Total; for (int i = 0; i < N; i++) { cin >> a[i]; } if (a[0] + a[1] != a[0] * a[1]) { dp[0][a[0]+a[1]] = "+"; dp[0][a[0]*a[1]] = "*"; } else { dp[0][a[0]+a[1]] = "+"; } for (int i = 0; i < N-1; i++) { for (int j = 1; j <= Total; j++) { if (!dp[i][j].empty()) { int tmp = j * a[i+2]; if (tmp <= Total) { dp[i+1][tmp] = max(dp[i+1][tmp], dp[i][j]+"*"); } tmp = j + a[i+2]; if (tmp <= Total) { dp[i+1][tmp] = max(dp[i+1][tmp], dp[i][j]+"+"); } } } } cout << dp[N-2][Total] << endl; return 0; }