Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- using ll = long long;
- using ld = long double;
- using pii = pair<int, int>;
- constexpr int N = (1 << 10);
- int ans[N], num[9], n, t, answer = 0;
- char c;
- string s[] = {
- "111000000",
- "000111000",
- "000000111",
- "100100100",
- "010010010",
- "001001001",
- "100010001",
- "001010100"
- };
- bool getbit(int mask, int i){
- return (mask & (1 << i));
- }
- bool check(int mask){
- for (int i = 0; i < 8; i++)
- if (mask == num[i])
- return true;
- return false;
- }
- void dfs(int mask = 0){
- if (check(mask))
- return;
- bool used[10];
- for (int i = 0; i < 9; i++){
- if (!(getbit(mask, i))){
- if (!ans[mask ^ (1 << i)])
- dfs(mask ^ (1 << i));
- used[ans[mask ^ (1 << i)]] = 1;
- }
- }
- for (int i = 0; i < 10; i++)
- if (!used[i]){
- ans[mask] = i;
- return;
- }
- }
- void Solve(){
- for (int i = 0; i < 8; i++)
- for (int j = 0; j < 9; j++)
- if (s[i][j] == '1')
- num[i] += (1 << j);
- dfs();
- cin >> n;
- while(n--){
- t = 0;
- for (int i = 0; i < 9; i++){
- cin >> c;
- if (c == 'X')
- t += (1 << i);
- }
- answer ^= ans[t];
- }
- cout << (answer ? "First" : "Second");
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- Solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement