結果
問題 |
No.10 +か×か
|
ユーザー |
![]() |
提出日時 | 2020-10-13 14:43:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 5,000 ms |
コード長 | 927 bytes |
コンパイル時間 | 1,563 ms |
コンパイル使用メモリ | 173,400 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-14 15:46:34 |
合計ジャッジ時間 | 2,157 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
ソースコード
/** * @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+1,vector<bool>(k+1,false)); dp[n][t] = true; for (int i = n-1; i >= 0; i--) { for (int j = 0; j <= t; j++) { if (!dp[i+1][j]) continue; if (j - a[i] <= k && j - a[i] >= 0) dp[i][j-a[i]] = true; if (j % a[i] == 0 && j / a[i] <= k) dp[i][j/a[i]] = true; } } int now = a[0]; for (int i = 2; i <= n; i++) { if (now+a[i-1] <= k && dp[i][now+a[i-1]]) { cout << '+'; now += a[i-1]; } else { cout << '*'; now *= a[i-1]; } } cout << endl; return 0; }