結果
問題 | No.10 +か×か |
ユーザー | ldsyb |
提出日時 | 2017-07-18 19:36:41 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 28 ms / 5,000 ms |
コード長 | 618 bytes |
コンパイル時間 | 541 ms |
コンパイル使用メモリ | 67,052 KB |
実行使用メモリ | 42,376 KB |
最終ジャッジ日時 | 2023-08-21 06:23:25 |
合計ジャッジ時間 | 1,354 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 28 ms
42,376 KB |
testcase_04 | AC | 13 ms
28,920 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 27 ms
42,344 KB |
testcase_07 | AC | 15 ms
29,072 KB |
testcase_08 | AC | 6 ms
10,892 KB |
testcase_09 | AC | 9 ms
17,132 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 2 ms
4,380 KB |
ソースコード
#include <iostream> #include <algorithm> using namespace std; int main(){ int64_t n, total; cin >> n >> total; int64_t a[n], inf = 1ll << n; for(int i = 0; i < n; i++) cin >> a[i]; int64_t dp[n][total + 1]; fill(dp[0], dp[n], inf); dp[0][a[0]] = 0; for(int i = 1; i < n; i++) for(int j = 0; j <= total; j++) if(dp[i - 1][j] != inf){ if(j + a[i] <= total) dp[i][j + a[i]] = min(dp[i][j + a[i]], 2 * dp[i - 1][j]); if(j * a[i] <= total) dp[i][j * a[i]] = min(dp[i][j * a[i]], 2 * dp[i - 1][j] + 1); } for(int i = n - 2; 0 <= i; i--) cout << ((dp[n - 1][total] >> i) % 2 == 0 ? '+' : '*'); cout << endl; }