結果

問題 No.102 トランプを奪え
ユーザー outlineoutline
提出日時 2021-02-10 19:32:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,368 ms / 5,000 ms
コード長 2,966 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 138,236 KB
実行使用メモリ 222,256 KB
最終ジャッジ日時 2023-09-22 15:09:48
合計ジャッジ時間 6,503 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
222,200 KB
testcase_01 AC 104 ms
222,172 KB
testcase_02 AC 131 ms
222,180 KB
testcase_03 AC 104 ms
222,252 KB
testcase_04 AC 104 ms
222,256 KB
testcase_05 AC 238 ms
222,100 KB
testcase_06 AC 179 ms
222,156 KB
testcase_07 AC 123 ms
222,100 KB
testcase_08 AC 211 ms
222,184 KB
testcase_09 AC 1,368 ms
222,104 KB
testcase_10 AC 1,267 ms
222,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int dp[14][14][14][14][27][27][2];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    vector<int> N(4);
    for(int i = 0; i < 4; ++i)  cin >> N[i];

    for(int a = 0; a <= 13; ++a){
        for(int b = 0; b <= 13; ++b){
            for(int c = 0; c <= 13; ++c){
                for(int d = 0; d <= 13; ++d){
                    for(int e = 0; e <= 26; ++e){
                        for(int f = 0; f <= 26; ++f){
                            for(int g = 0; g <= 1; ++g){
                                dp[a][b][c][d][e][f][g] = -1;
                            }
                        }
                    }
                }
            }
        }
    }

    auto func = [&](auto&& self, vector<int> card, vector<int> score, int t) -> int {
        if(dp[card[0]][card[1]][card[2]][card[3]][score[0]][score[1]][t] != -1){
            return dp[card[0]][card[1]][card[2]][card[3]][score[0]][score[1]][t];
        }
        if(card[0] + card[1] + card[2] + card[3] == 0){
            return dp[0][0][0][0][score[0]][score[1]][t] = (score[0] > score[1]) ^ t;
        }

        int res = 1;
        for(int i = 0; i < 4; ++i){
            for(int j = 1; j <= 3; ++j){
                if(card[i] - j >= 0){
                    card[i] -= j;
                    score[t] += j;
                    if(card[i] - j > 0){
                        res &= self(self, card, score, t ^ 1);
                    }
                    else{
                        int delta = (score[t ^ 1] + 1) / 2;
                        score[t] += delta;
                        score[t ^ 1] -= delta;
                        res &= self(self, card, score, t ^ 1);
                        score[t] -= delta;
                        score[t ^ 1] += delta;
                    }
                    card[i] += j;
                    score[t] -= j;
                }
            }
        }

        return dp[card[0]][card[1]][card[2]][card[3]][score[0]][score[1]][t] = res ^ 1;
    };

    cout << (func(func, N, {0, 0}, 0) ? "Taro" : "Jiro") << endl;

    return 0;
}
0