結果

問題 No.361 門松ゲーム2
ユーザー HachimoriHachimori
提出日時 2016-04-17 23:19:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 262 ms / 2,000 ms
コード長 1,207 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 56,616 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 02:26:48
合計ジャッジ時間 1,620 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 90 ms
6,944 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 29 ms
6,940 KB
testcase_17 AC 11 ms
6,940 KB
testcase_18 AC 7 ms
6,940 KB
testcase_19 AC 8 ms
6,944 KB
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 31 ms
6,944 KB
testcase_22 AC 262 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 5 ms
6,940 KB
testcase_26 AC 14 ms
6,944 KB
testcase_27 AC 17 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int grundy(int, int*)’:
main.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
   46 | }
      | ^

ソースコード

diff #

// yukicoder 361
// Grundy Number
//
// def f(s):
//     x = set()
//     for t in (状態 s から遷移可能な状態全体):
//         x.add(f(t))
//     return x に含まれない数字の中で最も小さい 0 以上の数

#include<iostream>
#include<cstring>
using namespace std;
const int BUF = 505;


int L, D;

void read() {
    cin >> L >> D;
}


int grundy(int s, int dp[BUF]) {
    int &ret = dp[s];
    if (ret != -1) return ret;
    
    bool isAvail[BUF] = {};

    for (int len1 = 1; len1 < s; ++len1) {
        for (int len2 = 1; len1 + len2 < s; ++len2) {
            if (len1 == len2) continue;
            
            int len3 = s - len1 - len2;
            if (len1 == len3 || len2 == len3) continue;
            if (max(len1, max(len2, len3)) - min(len1, min(len2, len3)) > D) continue;

            isAvail[grundy(len1, dp) ^ grundy(len2, dp) ^ grundy(len3, dp)] = true;
        }
    }

    for (int i = 0; i < BUF; ++i) {
        if (!isAvail[i]) {
            return ret = i;
        }
    }
}


void work() {
    int dp[BUF];
    memset(dp, -1, sizeof(dp));
    cout << (grundy(L, dp) ? "kado" : "matsu") << endl;
}


int main() {
    read();
    work();
    return 0;
}
0