結果

問題 No.10 +か×か
ユーザー 👑 NachiaNachia
提出日時 2020-09-27 12:51:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 831 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 165,416 KB
実行使用メモリ 8,144 KB
最終ジャッジ日時 2023-08-21 06:32:19
合計ジャッジ時間 2,253 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int N, Res;
int A[50];
bool dp[50][100001] = {};

int main() {
    cin >> N >> Res;
    rep(i, N) cin >> A[i]; reverse(A, A + N);
    dp[0][Res] = true;
    for (int i = 0; i < N - 1; i++) {
        rep(j, 100001) {
            if (j % A[i] == 0) dp[i + 1][j / A[i]] = dp[i + 1][j / A[i]] || dp[i][j];
            if (j - A[i] >= 0) dp[i + 1][j - A[i]] = dp[i + 1][j - A[i]] || dp[i][j];
        }
    }

    string ans;
    int p = A[N - 1];
    for (int i = N - 2; i >= 0; i--) {
        if (p + A[i] <= 100000) if (dp[i][p + A[i]]) {
            ans += "+"; p = p + A[i];
            continue;
        }
        ans += "*"; p = p * A[i];
    }

    cout << ans << endl;

    return 0;
}
0