結果

問題 No.102 トランプを奪え
ユーザー kimiyukikimiyuki
提出日時 2016-09-13 22:14:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,260 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 90,640 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 13:15:01
合計ジャッジ時間 1,494 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <map>
#include <tuple>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }

const int win  = 1;
const int draw = 0;
const int lose = -1;
int solve(array<int,4> n, int a, int b) {
    if (b < a) return - solve(n, b, a);
    whole(sort, n);
    static map<tuple<array<int,4>, int, int>, int> memo;
    auto key = make_tuple(n, a, b);
    if (memo.count(key)) return memo[key];
    int result = -2;
    repeat (i,4) {
        repeat_from (d, 1, min(3,n[i])+1) {
            n[i] -= d;
            int c = n[i] ? 0 : (b+1)/2;
            setmax(result, solve(n, a+d+c, b-c));
            n[i] += d;
        }
    }
    if (result == -2) {
        result = a > b ? win : a < b ? lose : draw;
    }
    return memo[key] = result;
}
int main() {
    array<int,4> n; cin >> n[0] >> n[1] >> n[2] >> n[3];
    int ans = solve(n, 0, 0);
    cout << (ans == win ? "Taro" : ans == lose ? "Jiro" : "Draw") << endl;
    return 0;
}
0