結果

問題 No.10 +か×か
ユーザー momoyuumomoyuu
提出日時 2023-03-16 14:50:23
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 861 bytes
コンパイル時間 3,290 ms
コンパイル使用メモリ 251,856 KB
実行使用メモリ 23,668 KB
最終ジャッジ日時 2023-10-18 13:01:45
合計ジャッジ時間 3,805 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 22 ms
23,668 KB
testcase_04 AC 16 ms
16,804 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 22 ms
23,668 KB
testcase_07 AC 15 ms
16,804 KB
testcase_08 AC 6 ms
7,368 KB
testcase_09 AC 9 ms
10,996 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n;
    int t;
    cin>>n>>t;
    vector<int> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    vector<vector<int> > dp(n+1,vector<int>(t+1,0));
    dp[n][t] = 1;
    for(int i = n;i>=1;i--){
        for(int j = 0;j<=t;j++){
            if(dp[i][j]==0) continue;
            int nj = j - a[i-1];
            if(nj>=0) dp[i-1][nj] = 1;
            if(j%a[i-1]==0){
                nj = j / a[i-1];
                dp[i-1][nj] = 1;
            }
        }
    }
    assert(dp[1][a[0]]==1);
    string ans = "";
    int now = a[0];
    for(int i = 1;i<n;i++){
        int nxt = now + a[i];
        if(nxt<=t&&dp[i+1][nxt]){
            now = nxt;
            ans += "+";
        }else{
            now = now * a[i];
            ans += "*";
        }
    }
    cout<<ans<<endl;
}

0