結果

問題 No.10 +か×か
ユーザー drymousedrymouse
提出日時 2024-02-17 09:09:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,078 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 71,480 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-02-17 09:09:03
合計ジャッジ時間 2,523 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
using namespace std;

int main(void) {
    int N, Total;
    cin >> N >> Total;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    string turtle[Total + 1];
    for (int i = 0; i < Total + 1; i++) {
        turtle[i] = "!";
    }
    turtle[A[0]] = "";
    for (int i = 1; i < N; i++) {
        for (int j = Total; j >= 0; j--) {
            if (turtle[j][0] != '!') {
                if (j + A[i] <= Total) {
                    string cand = turtle[j] + "+";
                    if (cand.size() > turtle[j+A[i]].size() || cand.compare(turtle[j+A[i]]) > 0) {
                        turtle[j+A[i]] = cand;
                    }
                }
                if (j * A[i] <= Total) {
                    string cand = turtle[j] + "*";
                    if (cand.size() > turtle[j*A[i]].size() || cand.compare(turtle[j*A[i]]) > 0) {
                        turtle[j*A[i]] = cand;
                    }
                }
            }
        }
    }

    cout << turtle[Total] << endl;
    
    return 0;
}
0