結果

問題 No.1613 Rush and Remove
ユーザー milanis48663220
提出日時 2021-07-21 22:37:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,836 bytes
コンパイル時間 1,251 ms
コンパイル使用メモリ 123,708 KB
最終ジャッジ日時 2025-01-23 04:48:16
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

int grundy[100];

int mex(vector<int> v){
    int mx = *max_element(v.begin(), v.end());
    vector<bool> used(mx+2);
    for(int x: v) used[x] = true;
    for(int i = 0; i <= mx+1; i++){
        if(!used[i]) return i;
    }
    assert(false);
}

int popcount(int n){
    int ans = 0;
    for(int i = 0; i < 20; i++){
        if(n&(1<<i)) ans++;
    }
    return ans;
}

int MAX_BIT = 15;

vector<int> base2(int x){
    vector<int> ans(MAX_BIT);
    for(int i = 0; i < MAX_BIT; i++){
        if(x&(1<<i)) ans[i] = 1;
    }
    return ans;
}

bool ok(int x, int y){
    auto vx = base2(x);
    auto vy = base2(y);
    auto ok = [&](int i, int j){
        assert(j <= i);
        if(vx[i] != 1) return false;
        for(int k = j; k < i; k++){
            if(vx[k] == 1) return false;
        }
        return true;
    };
    auto convert = [&](int i, int j){
        assert(j <= i);
        vector<int> ans = vx;
        ans[i] = 0;
        for(int k = j; k < i; k++){
            ans[k] = 1;
        }
        return ans;
    };
    for(int i = 0; i < MAX_BIT; i++){
        for(int j = 0; j <= i; j++){
            if(ok(i, j) && vy == convert(i, j)) return true;
        }
    }
    return false;
}

void test(){
    grundy[0] = 0;
    for(int i = 1; i < 100; i++){
        vector<int> v;
        for(int j = 0; j < i; j++){
            if(ok(i, j)) v.push_back(grundy[j]);
        }
        grundy[i] = mex(v);
    }
    for(int i = 0; i < 100; i++) cout << i << ':' << grundy[i] << endl;
}

int mod3(vector<int> v){
    int cur = 1;
    int ans = 0;
    for(int x: v){
        ans += cur*x;
        ans %= 3;
        cur *= 2;
        cur %= 3;
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    // test();
    int h, w; cin >> h >> w;
    vector<string> b(h);
    for(int i = 0; i < h; i++) cin >> b[i];
    int xo = 0;
    for(int j = 0; j < w; j++){
        vector<int> v;
        for(int i = 0; i < h; i++) {
            if(b[i][j] == 'o') v.push_back(1);
            else v.push_back(0);
        }
        xo ^= mod3(v);
    }
    if(xo == 0) cout << "Second" << endl;
    else cout << "First" << endl;
}
0