結果

問題 No.10 +か×か
コンテスト
ユーザー tottoripaper
提出日時 2014-11-16 04:21:47
言語 C++11(廃止可能性あり)
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,160 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 477 ms
コンパイル使用メモリ 59,756 KB
実行使用メモリ 47,860 KB
最終ジャッジ日時 2025-12-06 14:29:23
合計ジャッジ時間 1,485 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |     scanf("%d %d", &N, &total);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:13:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |     for(int i=0;i<N;i++){scanf("%d", A+i);}
      |                          ~~~~~^~~~~~~~~~~

ソースコード

diff #
raw source code

#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