結果

問題 No.102 トランプを奪え
ユーザー not_522not_522
提出日時 2015-08-17 18:07:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,000 bytes
コンパイル時間 1,352 ms
コンパイル使用メモリ 160,876 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 12:35:34
合計ジャッジ時間 2,134 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template<typename T> class Grundy {
private:
  map<T, int> grundy;

public:
  int solve(T t) {
    if (grundy.count(t)) return grundy[t];
    set<int> s;
    for (auto g : t.next()) s.insert(solve(g));
    for (int i = 0; ; ++i) {
      if (s.count(i) == 0) return grundy[t] = i;
    }
  }

  template<typename S> int solve(S s) {
    int g = 0;
    for (auto t : s) g ^= solve(t);
    return g;
  }
};

class Card {
private:
  int card;

public:
  Card() {}

  Card(int card) : card(card) {}

  vector<Card> next() {
    vector<Card> res;
    if (card >= 1) res.emplace_back(card - 1);
    if (card >= 2) res.emplace_back(card - 2);
    if (card >= 3) res.emplace_back(card - 3);
    return res;
  }

  bool operator<(const Card& c) const {
    return card < c.card;
  }
};

int main() {
  vector<Card> n(4);
  for (auto& i : n) {
    int j;
    cin >> j;
    i = j;
  }
  Grundy<Card> grundy;
  cout << (grundy.solve(n) ? "Taro" : "Jiro") << endl;
}
0