Grundy æ°ã¯ Grundy æ°ã§ãããå±±ãåå²ãã¦ãããã¨ããã¿ã¤ãã® Grundy æ°ã§ããã
åé¡æ¦è¦
åã®åºéãä¸ããããã åç®ã®åºé㯠ã¨ãªã£ã¦ããã
Alice 㨠Bob ã¯æ¬¡ã®ãããªã²ã¼ã ãè¡ãã
ã¾ã æ®ã£ã¦ããåºéã®ãã¡ããä»ã¾ã§ã«é¸ã°ããã©ã®åºéã¨ãå ±æç¹ããããªãããã®ã交äºã«é¸ãã§ãããå ã«åºéãé¸ã¹ãªããªã£ãæ¹ãè² ãã§ããã
åæ¹æåãå°½ãããã¨ããã©ã¡ããåã¤ãï¼
(ãã«ããã¹ãã±ã¼ã¹ï¼ å)
å¶ç´
èãããã¨
ã¨ããå°ããè¦ããå¶ç´ã«æå³ãããã®ããª...ã¨ããã®ãæåæã£ãããã®å¾ã ã¨ããå¶ç´ããããã座å§ããã°å®è³ªæå³ãªãå¶ç´ãªã®ããª... ã¨ãªã£ããã§ãã³ã³ãã¹ãçã«ã¯åº§å§ããªãã¦ãããã®ã¯æ¥½ã ãã
ããã¯ããã¨ãããããåºéã¹ã±ã¸ã¥ã¼ãªã³ã°åé¡ã®ãããªè¨å®ã§ã²ã¼ã ãããï¼ï¼ï¼ä»ã¾ã§ããããã§ãªãã£ãé¢ç½ãåé¡ã ãï¼ï¼ï¼
ãããããå±±ã¨ãç¤é¢ã¨ããåå²ããã¦è¡ããããªã²ã¼ã ãã¯ãGrundy æ°ã¨ç¸å ´ã¯æ±ºã¾ã£ã¦ããï¼ï¼ï¼
ç¤é¢ãåå²ãã¦ããã²ã¼ã
åæç¶æ ã ã¨ã²ã¼ã ã®ç¤é¢ã¯ã[0, 100) ã¨ããç¶æ ã«ãªã£ã¦ãã (åºéã®åº§æ¨ã 0-indexed ã«ãã)ã
ãããããã¨ãã° åã®åºéã®ä¸ã« [10, 20) ããã£ãã¨ä»®å®ãã¦ããããé¸ã¶ã¨ãç¤é¢ã¯
- [0, 10)
- [20, 100)
ã¨ããå
·åã«åå²ããããããã§ãç¤é¢ã ã®ç¯å²ã«å¶éããã¨ãã® Grundy æ°ã G[l][r]
ã¨æ¸ããã¨ã«ãããããã®ã¨ãããã®ããã«ãç¤é¢å
¨ä½ã 2 ã¤ã«åå²ãããç¶æ
ã®å±é¢ãã® Grundy æ°ã¯
G[0][10] ^ G[20][100]
ã«ãªããã¨ãç¥ããã¦ããããã£ã¦ã åã®åºé ããããã«å¯¾ãã¦ã
G[0][l[0]] ^ G[r[0]][100]
G[0][l[1]] ^ G[r[1]][100]
- ...
G[0][l[N-1]] ^ G[r[N-1]][100]
ã® mex ãæ±ããã° OKã
ã¡ã¢åå帰ã¸
以ä¸ã®ãã¨ãå帰çã«è¡ãã° OKãåºé ã«é¢ãã Grundy æ°ãã¡ã¢åããªãããG[0][100]
ãæ±ãããã
è¨ç®é㯠ã¨ãã¦ã ã¨ãªãã
#include <bits/stdc++.h> using namespace std; int MAX = 110; int N; vector<int> L, R; vector<vector<int>> dp; int solve(int left = 0, int right = MAX) { if (right == left) return 0; if (dp[left][right] != -1) return dp[left][right]; set<int> se; for (int i = 0; i < N; ++i) { if (left <= L[i] && R[i] <= right) { int tmp = solve(left, L[i]) ^ solve(R[i], right); se.insert(tmp); } } int grundy = 0; while (se.count(grundy)) ++grundy; return dp[left][right] = grundy; } int main() { int NUM_CASE; cin >> NUM_CASE; while (NUM_CASE--) { cin >> N; L.resize(N), R.resize(N); for (int i = 0; i < N; ++i) { cin >> L[i] >> R[i]; --L[i], --R[i]; } dp.assign(MAX, vector<int>(MAX+1, -1)); cout << (solve() > 0 ? "Alice" : "Bob") << endl; } }