結果

問題 No.10 +か×か
ユーザー yogi_cgyogi_cg
提出日時 2020-03-28 18:27:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,745 bytes
コンパイル時間 1,910 ms
コンパイル使用メモリ 173,320 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 18:05:57
合計ジャッジ時間 2,694 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 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 9 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

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

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    int Total; cin >> Total;
    vi A(N); REP(i, N) cin >> A[i];
    vvb dp(N+1, vb(100001, false)); dp[1][A[0]] = true;
    for(int i = 1; i < N; i++)
    {
        for(int j = 0; j <= 100000; j++)
        {
            if(dp[i][j])
            {
                if(j+A[i] <= 100000) dp[i+1][j+A[i]] = true;
                if(j*A[i] <= 100000) dp[i+1][j*A[i]] = true;
            }
        }
    }

    string ans = "";
    int t = Total;
    for(int i = N-1; i > 0; i--)
    {
        for(int j = 0; j <= Total; j++)
        {
            if(dp[i][j] && j+A[i] == t)
            {
                ans.push_back('+');
                t = j;
                break;
            }
            else if(dp[i][j] && j*A[i] == t)
            {
                ans.push_back('*');
                t = j;
                break;
            }
        }
    }
    reverse(ALL(ans));
    cout << ans << endl;
}
0