結果

問題 No.102 トランプを奪え
ユーザー izuru_matsuuraizuru_matsuura
提出日時 2016-09-13 21:57:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 404 ms / 5,000 ms
コード長 2,206 bytes
コンパイル時間 2,739 ms
コンパイル使用メモリ 185,420 KB
実行使用メモリ 11,308 KB
最終ジャッジ日時 2023-08-10 19:59:19
合計ジャッジ時間 3,728 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 28 ms
4,388 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 78 ms
5,172 KB
testcase_06 AC 88 ms
5,368 KB
testcase_07 AC 22 ms
4,380 KB
testcase_08 AC 117 ms
6,076 KB
testcase_09 AC 404 ms
11,308 KB
testcase_10 AC 385 ms
10,980 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< tuple<vector<int>, int, int>, int > cache;
    int dfs(vector<int> xs, int tscore, int t) {
        sort(xs.begin(), xs.end());
        auto key = make_tuple(xs, tscore, t);
        if (cache.count(key)) {
            return cache[key];
        }
        int sum = 0;
        for (int i = 0; i < 4; i++) sum += xs[i];
        int jscore = S - sum - tscore;
        int nscore = -1; // 譛€濶ッ謇九r縺ィ縺」縺溘→縺阪・莉頑焔逡ェ縺ョ莠コ縺ョ轤ケ謨ー  
        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 {
                    int z = dfs(xs, tscore - (xs[i] == 0 ? (tscore + 1) / 2 : 0), !t);
                    nscore = max(nscore, S - z);
                }
                xs[i] += j;
            }
        }
        return cache[key] = (flag ? (t ? nscore : S - 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