結果

問題 No.10 +か×か
ユーザー imulanimulan
提出日時 2016-06-20 17:57:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,000 ms / 5,000 ms
コード長 1,114 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 171,092 KB
実行使用メモリ 30,828 KB
最終ジャッジ日時 2023-08-21 06:19:59
合計ジャッジ時間 5,578 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,516 KB
testcase_01 AC 5 ms
9,564 KB
testcase_02 AC 4 ms
9,592 KB
testcase_03 AC 1,000 ms
30,500 KB
testcase_04 AC 488 ms
23,372 KB
testcase_05 AC 5 ms
9,520 KB
testcase_06 AC 894 ms
30,828 KB
testcase_07 AC 490 ms
23,220 KB
testcase_08 AC 97 ms
13,904 KB
testcase_09 AC 152 ms
19,152 KB
testcase_10 AC 6 ms
9,668 KB
testcase_11 AC 5 ms
9,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

string dp[100001],newdp[100001];

int main()
{
    int n,total;
    cin >>n >>total;
    vector<int> a(n);
    rep(i,n) cin >>a[i];

    fill(dp,dp+total+1,"#");
    dp[a[0]]="";

    for(int i=1; i<n; ++i)
    {
        fill(newdp,newdp+total+1,"#");
        for(int j=1; j<=total; ++j)
        {
            int nxt=j+a[i];
            if(nxt<=total)
            {
                if(newdp[nxt]=="#") newdp[nxt]=dp[j]+"+";
                else newdp[nxt]=max(newdp[nxt],dp[j]+"+");
            }

            nxt=j*a[i];
            if(nxt<=total)
            {
                if(newdp[nxt]=="#") newdp[nxt]=dp[j]+"*";
                else newdp[nxt]=max(newdp[nxt],dp[j]+"*");
            }
        }

        rep(j,total+1) dp[j]=newdp[j];
    }

    cout << dp[total] << endl;
    return 0;
}
0