結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
165,364 KB
testcase_01 AC 59 ms
163,148 KB
testcase_02 AC 60 ms
163,148 KB
testcase_03 AC 576 ms
311,848 KB
testcase_04 AC 68 ms
168,752 KB
testcase_05 AC 60 ms
167,232 KB
testcase_06 AC 581 ms
310,748 KB
testcase_07 AC 234 ms
212,316 KB
testcase_08 AC 91 ms
174,172 KB
testcase_09 AC 80 ms
168,848 KB
testcase_10 AC 61 ms
165,132 KB
testcase_11 AC 60 ms
165,316 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][100001]; //1..* 2..+
string dp_ans[51][100001];

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