結果

問題 No.10 +か×か
ユーザー tottoripapertottoripaper
提出日時 2014-11-16 04:21:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 1,160 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 52,988 KB
実行使用メモリ 47,516 KB
最終ジャッジ日時 2023-08-21 06:08:22
合計ジャッジ時間 1,427 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
47,356 KB
testcase_01 AC 17 ms
47,424 KB
testcase_02 AC 17 ms
47,228 KB
testcase_03 AC 44 ms
47,468 KB
testcase_04 AC 30 ms
47,408 KB
testcase_05 AC 17 ms
47,352 KB
testcase_06 AC 46 ms
47,468 KB
testcase_07 AC 36 ms
47,288 KB
testcase_08 AC 23 ms
47,228 KB
testcase_09 AC 26 ms
47,424 KB
testcase_10 AC 17 ms
47,516 KB
testcase_11 AC 17 ms
47,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<iostream>

const long long INF = 1001001001001001001;

int N, total, A[50];
bool can[50][100001];
long long ope[50][100001];

int main(){
    scanf("%d %d", &N, &total);

    for(int i=0;i<N;i++){scanf("%d", A+i);}

    std::fill(&can[0][0], &can[0][0]+50*100001, false);
    std::fill(&ope[0][0], &ope[0][0]+50*100001, INF);
    can[0][A[0]] = true;
    ope[0][A[0]] = 0ll;
    for(int i=1;i<N;i++){
        for(int j=0;j<=total;j++){
            if(j - A[i] >= 0 && can[i-1][j-A[i]]){
                can[i][j] = true;
                ope[i][j] = std::min(ope[i][j], ope[i-1][j-A[i]] << 1);
            }
            if(j % A[i] == 0 && can[i-1][j/A[i]]){
                can[i][j] = true;
                ope[i][j] = std::min(ope[i][j], (ope[i-1][j/A[i]] << 1) + 1ll);
            }
        }
    }
    
    // for(int i=0;i<N;i++){
    //     for(int j=0;j<=total;j++){
    //         printf("%d ", can[i][j]);
    //     }
    //     puts("");
    // }

    for(int i=N-2;i>=0;i--){
        if(ope[N-1][total] >> i & 1){putchar('*');}
        else{putchar('+');}
    }
    puts("");
}
0