結果

問題 No.102 トランプを奪え
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-13 21:39:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,122 bytes
コンパイル時間 1,994 ms
コンパイル使用メモリ 185,028 KB
実行使用メモリ 20,224 KB
最終ジャッジ日時 2024-04-28 13:12:31
合計ジャッジ時間 4,088 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 28 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 WA -
testcase_05 AC 95 ms
6,940 KB
testcase_06 AC 81 ms
6,944 KB
testcase_07 AC 27 ms
6,944 KB
testcase_08 AC 98 ms
6,944 KB
testcase_09 WA -
testcase_10 AC 789 ms
18,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        auto i = vs.begin();
        os << "[" << *i;
        for (++i; i != vs.end(); ++i) os << " " << *i;
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    vector<int> N;
    int S;
    void input() {
        N.resize(4); cin >> N;
        S = 0;
        for (int i = 0; i < 4; i++) S += N[i];
    }

    const int INF = 1<<28;

    map<vector<int>, map<int, int>> cache;
    int dfs(vector<int>& xs, int tscore, int t) {
        if (cache.count(xs) && cache[xs].count(tscore)) {
            return cache[xs][tscore];
        }
        int sum = 0;
        for (int i = 0; i < 4; i++) sum += xs[i];
        int jscore = S - sum - tscore;
        //int nscore = tscore; // 譛€濶ッ謇九r縺ィ縺」縺溘→縺阪・taro縺ョ轤ケ謨ー  
        int nscore = (t ? -1 : INF);
        int flag = false;
        for (int i = 0; i < 4; i++) {
            if (xs[i] == 0) continue;
            flag = true;
            for (int j = 1; j <= min(3, xs[i]); j++) {
                xs[i] -= j;
                if (t) {
                    nscore = max(nscore, dfs(xs, tscore + j + (xs[i] == 0 ? (jscore + 1) / 2 : 0), !t));
                } else {
                    nscore = min(nscore, dfs(xs, tscore - (xs[i] == 0 ? (tscore + 1) / 2 : 0), !t));
                }
                xs[i] += j;
            }
        }
        return cache[xs][tscore] = (flag ? nscore : tscore);
    }

    void solve() {
        int t = dfs(N, 0, 1);
        int j = S - t;
        if (t == j) {
            cout << "Draw" << endl;
        } else if (t > j) {
            cout << "Taro" << endl;
        } else {
            assert(t < j);
            cout << "Jiro" << endl;
        }
    }
}

int main() {
    input(); solve();
    return 0;
}

0