結果

問題 No.10 +か×か
ユーザー otamay6otamay6
提出日時 2019-10-17 17:50:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 803 bytes
コンパイル時間 1,793 ms
コンパイル使用メモリ 170,612 KB
実行使用メモリ 23,540 KB
最終ジャッジ日時 2023-09-07 02:03:32
合計ジャッジ時間 2,767 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,384 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]==-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