結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2015-04-16 00:57:50 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 18 ms / 5,000 ms |
コード長 | 751 bytes |
コンパイル時間 | 1,342 ms |
コンパイル使用メモリ | 164,832 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-14 15:29:24 |
合計ジャッジ時間 | 1,952 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#include "bits/stdc++.h" using namespace std; int main() { int N; cin >> N; int total; cin >> total; vector<long long> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } long long inf = 1ll << N; vector<long long> dp(total + 1, inf); dp[A[0]] = 0; for (int i = 1; i < N; i++) { vector<long long> dp2(total + 1, inf); for (int j = 0; j <= total; j++) { if (dp[j] == inf) continue; if (j + A[i] <= total){ dp2[j + A[i]] = min(dp2[j + A[i]], dp[j] * 2); } if (j * A[i] <= total){ dp2[j * A[i]] = min(dp2[j * A[i]], dp[j] * 2 + 1); } } dp = dp2; } for (int i = 0; i < N - 1; i++) { if ((dp[total] >> (N - 2 - i)) % 2 == 1){ cout << "*"; } else cout << "+"; } cout << endl; cin >> N; }