結果

問題 No.10 +か×か
ユーザー goodbatongoodbaton
提出日時 2015-07-16 00:33:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 579 ms / 5,000 ms
コード長 1,146 bytes
コンパイル時間 570 ms
コンパイル使用メモリ 75,048 KB
実行使用メモリ 312,456 KB
最終ジャッジ日時 2023-08-21 06:13:21
合計ジャッジ時間 3,431 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
165,196 KB
testcase_01 AC 59 ms
163,172 KB
testcase_02 AC 58 ms
163,020 KB
testcase_03 AC 576 ms
312,456 KB
testcase_04 AC 68 ms
168,680 KB
testcase_05 AC 61 ms
167,392 KB
testcase_06 AC 579 ms
310,576 KB
testcase_07 AC 237 ms
212,340 KB
testcase_08 AC 90 ms
174,272 KB
testcase_09 AC 81 ms
168,728 KB
testcase_10 AC 59 ms
165,144 KB
testcase_11 AC 60 ms
165,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 10000

bool dp[51][100000]; //1..* 2..+
string dp_ans[51][100000];

int main(){
    int n,total;
    int A[SIZE];
    string ans;
    
    scanf("%d%d",&n,&total);

    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    
    dp[1][A[0]]=true;
    
    for(int i=1;i<n;i++){
        
        for(int j=0;j<=total;j++){
            if(dp[i][j]==false) continue;
            
            if(j*A[i]<=total){
                dp_ans[i+1][j*A[i]]=max(dp_ans[i+1][j*A[i]],dp_ans[i][j]+'*');
                dp[i+1][j*A[i]]=true;
            }
            
            if(j+A[i]<=total){
                dp_ans[i+1][j+A[i]]=max(dp_ans[i+1][j+A[i]],dp_ans[i][j]+'+');
                dp[i+1][j+A[i]]=true;
            }
        }
    }
    
    cout << dp_ans[n][total] << endl;
    
    return 0;
}
0