結果

問題 No.10 +か×か
コンテスト
ユーザー tottoripaper
提出日時 2014-11-16 03:39:42
言語 C++11
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,007 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 464 ms
コンパイル使用メモリ 71,296 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2026-06-05 09:24:44
合計ジャッジ時間 1,541 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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