結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
ldsyb
|
| 提出日時 | 2017-07-18 19:36:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 5,000 ms |
| コード長 | 618 bytes |
| コンパイル時間 | 700 ms |
| コンパイル使用メモリ | 67,712 KB |
| 実行使用メモリ | 42,496 KB |
| 最終ジャッジ日時 | 2024-12-14 15:40:01 |
| 合計ジャッジ時間 | 1,399 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#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;
}
ldsyb