結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
ふーらくたる
|
| 提出日時 | 2017-02-17 02:13:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 839 ms / 5,000 ms |
| コード長 | 1,175 bytes |
| コンパイル時間 | 619 ms |
| コンパイル使用メモリ | 66,280 KB |
| 実行使用メモリ | 362,760 KB |
| 最終ジャッジ日時 | 2024-12-14 15:38:31 |
| 合計ジャッジ時間 | 4,934 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_N = 60;
const int MAX_TOTAL = 100010;
int a[MAX_N];
vector<char> dp[MAX_N][MAX_TOTAL];
int main() {
int n, total;
cin >> n >> total;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
// 初期化
for (int i = 0; i <= n; i++) {
for (int tot = 0; tot <= total; tot++) {
dp[i][tot] = vector<char>(i + 1, 0);
}
}
dp[0][a[0]] = vector<char>{'~'};
for (int i = 1; i < n; i++) {
for (int tot = 0; tot <= total; tot++) {
vector<char> hist;
// +
if (tot - a[i] >= 0) {
hist = dp[i - 1][tot - a[i]];
hist.push_back('+');
dp[i][tot] = max(dp[i][tot], hist);
}
// *
if (tot % a[i] == 0) {
hist = dp[i - 1][tot / a[i]];
hist.push_back('*');
dp[i][tot] = max(dp[i][tot], hist);
}
}
}
for (int i = 1; i < dp[n - 1][total].size(); i++) {
cout << dp[n - 1][total][i];
}
cout << endl;
return 0;
}
ふーらくたる