結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
203,744 KB
testcase_01 AC 78 ms
203,552 KB
testcase_02 AC 78 ms
203,592 KB
testcase_03 AC 612 ms
353,952 KB
testcase_04 WA -
testcase_05 AC 77 ms
203,588 KB
testcase_06 AC 625 ms
352,672 KB
testcase_07 AC 268 ms
252,384 KB
testcase_08 AC 113 ms
211,824 KB
testcase_09 AC 106 ms
208,424 KB
testcase_10 AC 78 ms
203,600 KB
testcase_11 AC 78 ms
203,596 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];
    }
    if (a[0] + a[1] != 0) {
        dp[0][a[0]+a[1]] = "+";
        dp[0][a[0]*a[1]] = "*";
    } else {
        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