結果

問題 No.10 +か×か
ユーザー yukitfyukitf
提出日時 2020-07-28 15:52:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 917 ms / 5,000 ms
コード長 1,749 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 174,708 KB
実行使用メモリ 395,016 KB
最終ジャッジ日時 2023-08-21 06:31:54
合計ジャッジ時間 5,501 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
18,748 KB
testcase_01 AC 10 ms
15,632 KB
testcase_02 AC 10 ms
15,648 KB
testcase_03 AC 917 ms
395,016 KB
testcase_04 AC 150 ms
162,472 KB
testcase_05 AC 118 ms
162,496 KB
testcase_06 AC 881 ms
393,504 KB
testcase_07 AC 375 ms
235,140 KB
testcase_08 AC 108 ms
93,228 KB
testcase_09 AC 90 ms
73,112 KB
testcase_10 AC 19 ms
28,072 KB
testcase_11 AC 17 ms
24,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vvi = vector<vi>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll N, Total; cin >> N >> Total;
    vl A(N); REP(i, N) cin >> A[i];

    vector<vs> dp(N, vs(100010, ""));
    dp[0][A[0]] = "$";

    for(ll i = 1; i < N; i++)
    {
        for(ll j = 0; j <= Total; j++)
        {
            if(dp[i-1][j] != "")
            {
                if(j+A[i] <= Total)
                {
                    if(dp[i][j+A[i]] == "") dp[i][j+A[i]] = dp[i-1][j] + "+";
                    chmax(dp[i][j+A[i]], dp[i-1][j] + "+");
                }
                if(j*A[i] <= Total) 
                {
                    if(dp[i][j*A[i]] == "") dp[i][j*A[i]] = dp[i-1][j] + "*";
                    chmax(dp[i][j*A[i]], dp[i-1][j] + "*");
                }
            }
        }
    }

    cout << dp[N-1][Total].substr(1, N-1) << endl;
}
0