結果

問題 No.10 +か×か
ユーザー otamay6otamay6
提出日時 2019-10-17 18:02:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 808 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 170,328 KB
実行使用メモリ 23,560 KB
最終ジャッジ日時 2023-09-07 02:21:36
合計ジャッジ時間 2,647 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 13 ms
10,688 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int N,T;cin>>N>>T;
    vector<vector<int>> prev(N+1,vector<int>(T+1,-1));
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    prev[1][A[0]]=0;
    REP(i,N){
        REP(j,T+1) if(prev[i][j]!=-1){
            if(j+A[i]<=T) prev[i+1][j+A[i]]=j;
        }
        REP(j,T+1) if(prev[i][j]!=-1){
            if(j*A[i]<=T&&prev[i+1][j*A[i]]==-1) prev[i+1][j*A[i]]=j;
        }
    }
    int j=T;
    string ans;
    for(int i=N;i>1;--i){
        int k=prev[i][j];
        if(j==A[i-1]+k) ans+='+';
        else ans+='*';
        j=k;
    }
    reverse(All(ans));
    cout<<ans<<endl;
}
0