結果

問題 No.361 門松ゲーム2
ユーザー emthrm
提出日時 2019-09-04 04:40:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,243 ms / 2,000 ms
コード長 1,486 bytes
コンパイル時間 1,234 ms
コンパイル使用メモリ 117,136 KB
最終ジャッジ日時 2025-01-07 16:26:45
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int d, grundy[501];

int rec(int l) {
  int &g = grundy[l];
  if (g != -1) return g;
  set<int> st;
  FOR(l1, 1, l) FOR(l2, 1, l) {
    int l3 = l - (l1 + l2);
    if (l3 <= 0) continue;
    if (l1 == l2 || l2 == l3 || l3 == l1) continue;
    if (max({l1, l2, l3}) - min({l1, l2, l3}) <= d) st.emplace(rec(l1) ^ rec(l2) ^ rec(l3));
  }
  g = 0;
  while (st.count(g) == 1) ++g;
  return g;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  memset(grundy, -1, sizeof(grundy));
  int l; cin >> l >> d;
  cout << (rec(l) == 0 ? "matsu\n" : "kado\n");
  return 0;
}
0