結果

問題 No.2285 Make A Unit Square
ユーザー milanis48663220milanis48663220
提出日時 2023-04-28 21:55:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 2,214 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 122,592 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 23:32:20
合計ジャッジ時間 2,276 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 148 ms
5,376 KB
testcase_03 AC 156 ms
5,376 KB
testcase_04 AC 131 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int mex(std::vector<int>)':
main.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
   53 | }
      | ^

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#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;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

int mex(vector<int> v){
    int n = v.size();
    vector<bool> used(n+1);
    for(int x: v){
        if(x <= n) used[x] = true;
    }
    for(int i = 0; i <= n; i++){
        if(!used[i]) return i;
    }
}

vector<int> calc(int n){
    vector<int> g(n+1);
    for(int x = 4; x <= n; x++){
        vector<int> v;
        for(int l = 2; l+2 <= x; l++){
            int r = x-l;
            v.push_back(g[l]^g[r]);
        }
        g[x] = mex(v);
    }
    // for(int i = 0; i <= n; i++){
    //     cout << g[i] << ' ';
    //     if(i%34 == 0) cout << endl;
    // }
    return g;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    auto g = calc(500);
    auto grundy = [&](int x){
        if(x < g.size()) return g[x];
        x %= 34;
        x += 34*5;
        return g[x];
    };
    int t; cin >> t;
    while(t--){
        int a, b; cin >> a >> b;
        ll x = grundy(a)^grundy(b);
        if(x == 0) cout << "Second" << endl;
        else cout << "First" << endl;
    }
}
0