結果
問題 |
No.10 +か×か
|
ユーザー |
![]() |
提出日時 | 2017-02-02 22:44:35 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 70 ms / 5,000 ms |
コード長 | 732 bytes |
コンパイル時間 | 582 ms |
コンパイル使用メモリ | 57,336 KB |
実行使用メモリ | 83,200 KB |
最終ジャッジ日時 | 2024-12-14 15:38:19 |
合計ジャッジ時間 | 1,850 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
#include <iostream> #include <cstring> using namespace std; int N; int total; int A[50]; unsigned long long dp[51][200000]; int main() { cin >> N >> total; for(int i = 0; i < N; i++) cin >> A[i]; memset(dp, -1, sizeof(dp)); dp[1][A[0]] = 0; for(int i = 1; i < N; i++) { for(int j = 0; j <= total; j++) { if(dp[i][j] != -1) { if(j * A[i] <= total) dp[i + 1][j * A[i]] = min(dp[i + 1][j * A[i]], dp[i][j] * 2 + 1); if(j + A[i] <= total) dp[i + 1][j + A[i]] = min(dp[i + 1][j + A[i]], dp[i][j] * 2); } } } string s; for(int i = N; i >= 2; i--) { if(dp[N][total] % 2 == 0) { s = "+" + s; }else{ s = "*" + s; } dp[N][total] /= 2; } cout << s << endl; }