結果

問題 No.102 トランプを奪え
ユーザー kuhakukuhaku
提出日時 2021-06-20 23:30:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 5,000 ms
コード長 5,290 bytes
コンパイル時間 2,586 ms
コンパイル使用メモリ 216,208 KB
実行使用メモリ 9,292 KB
最終ジャッジ日時 2023-09-05 01:45:37
合計ジャッジ時間 4,063 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
5,684 KB
testcase_01 AC 27 ms
5,508 KB
testcase_02 AC 31 ms
5,664 KB
testcase_03 AC 26 ms
5,440 KB
testcase_04 AC 26 ms
5,504 KB
testcase_05 AC 41 ms
5,668 KB
testcase_06 AC 38 ms
5,668 KB
testcase_07 AC 30 ms
5,668 KB
testcase_08 AC 41 ms
5,444 KB
testcase_09 AC 167 ms
9,292 KB
testcase_10 AC 155 ms
8,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vi = vector<int>;
using Vl = vector<ll>;
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define FORR(i, m, n) for(int i = (m)-1; i >= (n); --i)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FOR(i, 1, n+1)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n+1, 1)
#define all(s) (s).begin(), (s).end()
template <class T, class U>
bool chmax(T &a, const U b) { return a < b ? a = b, true : false; }
template <class T, class U>
bool chmin(T &a, const U b) { return b < a ? a = b, true : false; }
template <class T>
istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is>>i; return is; }
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (auto it=v.begin(); it!=v.end(); ++it) { os<<(it==v.begin()?"":" ")<<*it; } return os;
}
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    if constexpr(sizeof...(tail)==0) cout<<head<<'\n'; else cout<<head<<' ',co(forward<Tail>(tail)...);
}
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    if constexpr(sizeof...(tail)==0) cerr<<head<<'\n'; else cerr<<head<<' ',ce(forward<Tail>(tail)...);
}
template<typename T, typename... Args>
auto make_vector(T x, int arg, Args ...args) {
    if constexpr(sizeof...(args)==0) return vector<T>(arg, x); else return vector(arg,make_vector<T>(x, args...));
}
void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); }
void setp(const int n) { cout << fixed << setprecision(n); }
constexpr int64_t INF = 1000000000000000003;
constexpr int Inf = 1000000003;
constexpr int MOD = 1000000007;
constexpr int MOD_N = 998244353;
constexpr double EPS = 1e-7;
const double PI = acos(-1);

struct prime_number {
    const int sz = 1 << 22;
    bitset<1 << 22> is_not_prime;
    vector<int> data;

    prime_number() { init(); }

    void init() {
        is_not_prime[0] = is_not_prime[1] = true;
        for (int i = 2; i < sz; ++i) {
            if (!is_not_prime[i]) {
                data.emplace_back(i);
                if ((int64_t)i * i >= sz) continue;
                for (int j = i * i; j < sz; j += i) {
                    is_not_prime[j] = true;
                }
            }
        }
    }

    bool is_prime(int64_t n) {
        assert(n >= 0);
        if (n < sz) return !is_not_prime[n];
        for (auto i : data) {
            if ((int64_t)i * i > n) break;
            if (n % i == 0) return false;
        }
        return true;
    }

    vector<int> prime_numbers(int x) {
        vector<int> res;
        for (int i = 2; i <= x; ++i) {
            if (is_prime(i)) res.emplace_back(i);
        }
        return res;
    }

    // 素因数分解
    template <class T>
    vector<pair<T, int>> prime_factorization(T x) {
        if (x == 1) return vector<pair<T, int>>(1, {1, 1});
        vector<pair<T, int>> res;
        for (auto i : data) {
            int cnt = 0;
            for (; x % i == 0; x /= i) cnt++;
            if (cnt) res.emplace_back(i, cnt);
            if ((int64_t)i * i > x) break;
        }
        if (x != 1) res.emplace_back(x, 1);
        return res;
    }

    // 約数列挙
    template <class T>
    vector<T> divisors(T x) {
        auto v = prime_factorization(x);
        vector<T> res, a, b, cp;
        res.emplace_back(1);
        for (auto p : v) {
            int n = res.size();
            cp.resize(n);
            copy(res.begin(), res.end(), cp.begin());
            a.resize(n);
            T t = 1;
            for (int k = 0; k < p.second; ++k) {
                t *= p.first;
                for (int i = 0; i < n; ++i) a[i] = cp[i] * t;
                merge(res.begin(), res.end(), a.begin(), a.end(),
                      back_inserter(b));
                swap(res, b);
                b.clear();
            }
        }
        return res;
    }

    // 因数分解列挙
    template <class T>
    vector<vector<T>> factorization(T x) {
        vector<vector<T>> res;
        auto f = [&](auto self, vector<T> v, T a) -> void {
            if (a == 1) res.emplace_back(v);
            for (auto i : divisors(a)) {
                if (i == 1 || (!v.empty() && v.back() > i)) continue;
                v.emplace_back(i);
                self(self, v, a / i);
                v.pop_back();
            }
        };
        f(f, vector<T>(), x);
        return res;
    }
};
prime_number pn;

// clang-format on

int main(void) {
    vector<int> a(4);
    cin >> a;

    map<vector<int>, int> memo;
    auto f = [&](auto self, vector<int> &v) {
        bool flg = true;
        rep(i, 4) flg &= v[i] == 0;
        if (flg)
            return 0;
        if (memo.find(v) != memo.end())
            return memo[v];
        
        unordered_set<int> st;
        rep(i, 4) {
            repn(j, min(3, v[i])) {
                v[i] -= j;
                st.insert(self(self, v));
                v[i] += j;
            }
        }
        rep(i, 15) {
            if (st.find(i) == st.end())
                return memo[v] = i;
        }
        return 0;
    };

    if (f(f, a))
        puts("Taro");
    else
        puts("Jiro");

    return 0;
}
0