結果

問題 No.361 門松ゲーム2
ユーザー cormorancormoran
提出日時 2016-09-13 22:47:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 1,643 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 172,460 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-10 20:00:16
合計ジャッジ時間 2,885 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 53 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 16 ms
4,380 KB
testcase_22 AC 146 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 6 ms
4,376 KB
testcase_27 AC 8 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

class Solver {
  public:
    int L, D;
    vector<int> grundy;

    int calc_grundy(int l) {
        if(grundy[l] >= 0) return grundy[l];
        if(l < 6) {
            return grundy[l] = 0;
        } else {
            set<int> reachable;
            repeat(L1, 1, l + 1) {
                repeat(L2, L1 + 1, l - L1 + 1) {    
                    int L3 = l - L1 - L2;
                    if(L3 <= L2 or L3 - L1 > D) continue;                    
                    reachable.insert(calc_grundy(L1) ^ calc_grundy(L2) ^ calc_grundy(L3));
                }
            }
            if(reachable.size() == 0) {
                return grundy[l] = 0;
            }
            int mex = 0;
            for(int g : reachable) {
                if(mex == g) mex++;
            }
            return grundy[l] = mex;
        }
    }    
    
    
    bool solve() {
        cin >> L >> D;
        
        if(D == 1) {
            cout << "matsu" << endl;
            return 0;
        }
        grundy.resize(L + 1, -1);
        
        cout << (calc_grundy(L) != 0 ? "kado" : "matsu") << endl;
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0