結果

問題 No.10 +か×か
ユーザー mayoko_mayoko_
提出日時 2014-12-11 17:28:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,128 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 75,584 KB
実行使用メモリ 353,940 KB
最終ジャッジ日時 2023-09-02 14:00:02
合計ジャッジ時間 4,217 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
203,552 KB
testcase_01 AC 92 ms
203,556 KB
testcase_02 AC 93 ms
203,564 KB
testcase_03 AC 683 ms
353,940 KB
testcase_04 WA -
testcase_05 AC 107 ms
203,576 KB
testcase_06 AC 619 ms
352,840 KB
testcase_07 AC 265 ms
252,520 KB
testcase_08 AC 115 ms
211,892 KB
testcase_09 AC 106 ms
208,452 KB
testcase_10 AC 77 ms
203,676 KB
testcase_11 AC 77 ms
203,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define INF 1000000000

using namespace std;
typedef long long ll;
const int MAXN = 64;

string dp[MAXN][100100];
int a[MAXN];

int main(void) {
    int N, Total;
    cin >> N;
    cin >> Total;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    dp[0][a[0]+a[1]] = "+";
    dp[0][a[0]*a[1]] = "*";
    for (int i = 0; i < N-1; i++) {
        for (int j = 1; j <= Total; j++) {
            if (!dp[i][j].empty()) {
                int tmp = j * a[i+2];
                if (tmp <= Total) {
                    dp[i+1][tmp] = max(dp[i+1][tmp], dp[i][j]+"*");
                }
                tmp = j + a[i+2];
                if (tmp <= Total) {
                    dp[i+1][tmp] = max(dp[i+1][tmp], dp[i][j]+"+");
                }
            }
        }
    }
    cout << dp[N-2][Total] << endl;
    return 0;
}
0