結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2020-10-13 14:23:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 996 bytes |
| コンパイル時間 | 1,948 ms |
| コンパイル使用メモリ | 178,648 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-20 18:26:19 |
| 合計ジャッジ時間 | 2,706 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 5 |
ソースコード
/**
* @FileName a.cpp
* @Author kanpurin
* @Created 2020.10.13 14:23:01
**/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
int n;cin >> n;
int t;cin >> t;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int k = max(10,t);
vector<vector<bool>> dp(n,vector<bool>(k+1,false));
dp[0][a[0]] = true;
for (int i = 0; i < n-1; i++) {
for (int j = 0; j <= t; j++) {
if (!dp[i][j]) continue;
if (j + a[i+1] <= k) dp[i+1][j+a[i+1]] = true;
if (j * a[i+1] <= k) dp[i+1][j*a[i+1]] = true;
}
}
stack<int> sta;
int now = t;
vector<char> ans(n-1);
for (int i = n - 2; i >= 0; i--) {
if (dp[i][now-a[i+1]]) now -= a[i+1], ans[i] = '+';
else if (now % a[i+1] == 0 && dp[i][now/a[i+1]]) now /= a[i+1], ans[i] = '*';
}
for (int i = 0; i < n-1; i++) {
cout << ans[i];
}
cout << endl;
return 0;
}
🍮かんプリン