結果

問題 No.10 +か×か
ユーザー hanasoccer4hanasoccer4
提出日時 2019-02-05 14:59:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 669 ms / 5,000 ms
コード長 928 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 86,228 KB
実行使用メモリ 306,828 KB
最終ジャッジ日時 2023-08-21 06:25:28
合計ジャッジ時間 3,790 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
162,752 KB
testcase_01 AC 60 ms
162,708 KB
testcase_02 AC 60 ms
162,912 KB
testcase_03 AC 669 ms
306,828 KB
testcase_04 AC 127 ms
163,980 KB
testcase_05 AC 58 ms
162,716 KB
testcase_06 AC 669 ms
305,652 KB
testcase_07 AC 294 ms
207,448 KB
testcase_08 AC 106 ms
169,636 KB
testcase_09 AC 111 ms
166,400 KB
testcase_10 AC 59 ms
162,712 KB
testcase_11 AC 59 ms
162,708 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