結果

問題 No.8 N言っちゃダメゲーム
ユーザー nnenn0nnenn0
提出日時 2021-07-12 21:00:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,994 bytes
コンパイル時間 4,270 ms
コンパイル使用メモリ 265,416 KB
実行使用メモリ 814,788 KB
最終ジャッジ日時 2023-09-14 20:45:45
合計ジャッジ時間 6,492 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,892 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace atcoder;
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define rrep(i,a,b) for(int i = a; i >= b; i--)
#define fore(i,a) for(auto& i : a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt __builtin_popcount
#define loop while(true)
using ll = long long;
using pint = pair<int, int>;
using pll = pair<long long, long long>;
using NGraph = vector<vector<int>>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int IINF = 1000100100;
const long long LINF = 1LL << 60;
template<class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; }
template<class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); }
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; }

int get_grundy_s(int x, vector<int>& grundy, int N, int K) {
    if (grundy[x] != -1) return grundy[x];
    set<int> se;
    for (int i = x+1; i <= min(x+K, N-1); ++i) {
        se.insert(get_grundy_s(i, grundy, N, K));
    }

    int subgame = 0;
    while (se.count(subgame)) subgame++;

    return grundy[x] = subgame;
}

int get_grundy_bs(int x, vector<int>& grundy, int N, int K) {
    if (grundy[x] != -1) return grundy[x];
    bitset<121000> bs;
    for (int i = x+1; i <= min(x+K, N-1); ++i) {
        bs.set(1<<get_grundy_bs(i, grundy, N, K));
    }

    int subgame = 0;
    while (bs[1<<subgame]) subgame++;

    return grundy[x] = subgame;
}

int main() {
    int p; cin >> p;
    for (int i = 0; i < p; ++i) {
        int n, k; cin >> n >> k;
        vector<int> grundy(n, -1);
        int result = get_grundy_bs(0, grundy, n, k);
        if (result) cout << "Win" << endl;
        else cout << "Lose" << endl;
    }
    return 0;
}
0