結果

問題 No.1613 Rush and Remove
ユーザー milanis48663220milanis48663220
提出日時 2021-07-21 22:37:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,836 bytes
コンパイル時間 1,391 ms
コンパイル使用メモリ 125,932 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 18:51:54
合計ジャッジ時間 2,853 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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