結果

問題 No.10 +か×か
ユーザー tottoripapertottoripaper
提出日時 2014-11-16 03:39:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,007 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 52,432 KB
実行使用メモリ 12,832 KB
最終ジャッジ日時 2023-08-30 07:06:41
合計ジャッジ時間 1,487 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,168 KB
testcase_01 AC 6 ms
9,136 KB
testcase_02 AC 5 ms
9,372 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 6 ms
9,324 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 10 ms
10,212 KB
testcase_10 AC 5 ms
9,188 KB
testcase_11 AC 6 ms
9,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<iostream>

int N, total, A[50];
bool can[50][100001];
char 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);
    can[0][A[0]] = true;
    for(int i=0;i<N-1;i++){
        for(int j=0;j<=total;j++){
            if(!can[i][j]){continue;}

            if(j * A[i+1] <= total && ope[i+1][j*A[i+1]] != '+'){
                can[i+1][j*A[i+1]] = true;
                ope[i+1][j*A[i+1]] = '*';
            }
            if(j + A[i+1] <= total){
                can[i+1][j+A[i+1]] = true;
                ope[i+1][j+A[i+1]] = '+';
            }
        }
    }

    char opes[50];
    int length = 0;

    for(int i=N-1;i>0;i--){
        opes[length++] = ope[i][total];
        if(ope[i][total] == '+'){total -= A[i];}
        else{total /= A[i];}
    }

    for(int i=N-2;i>=0;i--){
        putchar(opes[i]);
    }
    puts("");
}
0