結果

問題 No.10 +か×か
ユーザー drymousedrymouse
提出日時 2024-02-17 09:52:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 349 ms / 5,000 ms
コード長 1,107 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 71,352 KB
実行使用メモリ 14,720 KB
最終ジャッジ日時 2024-02-17 09:52:17
合計ジャッジ時間 2,582 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 349 ms
14,592 KB
testcase_04 AC 11 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 324 ms
14,720 KB
testcase_07 AC 111 ms
11,520 KB
testcase_08 AC 22 ms
6,676 KB
testcase_09 AC 22 ms
8,576 KB
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] != '!' && turtle[j].size() == i - 1) {
                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