結果

問題 No.10 +か×か
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-10-13 14:23:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 996 bytes
コンパイル時間 1,491 ms
コンパイル使用メモリ 174,232 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 00:02:41
合計ジャッジ時間 2,310 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 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,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;
}
0