結果

問題 No.10 +か×か
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-10-13 14:43:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 927 bytes
コンパイル時間 1,737 ms
コンパイル使用メモリ 171,676 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 06:32:13
合計ジャッジ時間 2,480 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 8 ms
4,380 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @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;
}
0