結果

問題 No.10 +か×か
ユーザー hana314hana314
提出日時 2019-02-05 15:21:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 675 ms / 5,000 ms
コード長 928 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 85,232 KB
実行使用メモリ 306,764 KB
最終ジャッジ日時 2023-08-21 06:25:32
合計ジャッジ時間 3,722 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
162,640 KB
testcase_01 AC 61 ms
162,812 KB
testcase_02 AC 61 ms
162,820 KB
testcase_03 AC 669 ms
306,764 KB
testcase_04 AC 130 ms
164,064 KB
testcase_05 AC 61 ms
162,800 KB
testcase_06 AC 675 ms
305,544 KB
testcase_07 AC 297 ms
207,536 KB
testcase_08 AC 108 ms
169,620 KB
testcase_09 AC 112 ms
166,372 KB
testcase_10 AC 60 ms
162,728 KB
testcase_11 AC 61 ms
162,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<functional>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

int N,T,a[51];
string dp[51][100010]={};
int main(){
    cin >>N>>T;
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<=T;j++){
            dp[i][j]="&";
        }
    }
    dp[0][a[0]]="";
    for(int i=1;i<N;i++){
        for(int j=1;j<=T;j++){
            if(dp[i-1][j]!="&"){
                if(j+a[i]<=T){
                    dp[i][j+a[i]]=max(dp[i-1][j]+"+",dp[i][j+a[i]]);
                }
                if(j*a[i]<=T){
                     dp[i][j*a[i]]=max(dp[i-1][j]+"*",dp[i][j*a[i]]);
                }
            }
        }
    }
    cout<<dp[N-1][T]<<endl;
    return 0;
}
0