-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy path2207 - Grundy's Game.cpp
44 lines (39 loc) · 969 Bytes
/
2207 - Grundy's Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
Problem Name: Grundy's Game
Problem Link: https://cses.fi/problemset/task/2207
Author: Sachin Srivastava (mrsac7)
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int mxN = 1e6+6;
vector<int> dp = {0, 0, 0};
int mex(vector<int> v) {
set<int> s;
for (auto i: v)
s.insert(i);
for (int i = 0; i < mxN; i++) {
if (s.count(i) == 0) return i;
}
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r" , stdin);
freopen("output.txt", "w", stdout);
#endif
int t; cin>>t;
for (int i = 3; i < 2000; i++) {
vector<int> v;
for (int j = 1; i-j > j; j++) {
v.push_back(dp[j]^dp[i-j]);
}
dp.push_back(mex(v));
}
while(t--) {
int n; cin>>n;
if (n >= 2000) cout<<"first"<<endl;
else cout<< (dp[n] > 0 ? "first" : "second")<<endl;
}
}