結果

問題 No.715 集合と二人ゲーム
ユーザー kimiyukikimiyuki
提出日時 2018-08-06 21:46:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,440 bytes
コンパイル時間 3,088 ms
コンパイル使用メモリ 210,060 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2023-10-19 22:18:06
合計ジャッジ時間 8,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 5 ms
4,348 KB
testcase_04 AC 7 ms
4,348 KB
testcase_05 AC 7 ms
4,348 KB
testcase_06 AC 8 ms
4,348 KB
testcase_07 AC 10 ms
4,348 KB
testcase_08 AC 10 ms
4,348 KB
testcase_09 AC 12 ms
4,348 KB
testcase_10 AC 11 ms
4,348 KB
testcase_11 AC 13 ms
4,348 KB
testcase_12 AC 14 ms
4,348 KB
testcase_13 AC 15 ms
4,348 KB
testcase_14 AC 17 ms
4,348 KB
testcase_15 AC 18 ms
4,348 KB
testcase_16 AC 19 ms
4,348 KB
testcase_17 AC 18 ms
4,348 KB
testcase_18 AC 21 ms
4,348 KB
testcase_19 AC 21 ms
4,348 KB
testcase_20 AC 24 ms
4,348 KB
testcase_21 AC 24 ms
4,348 KB
testcase_22 AC 26 ms
4,348 KB
testcase_23 AC 25 ms
4,348 KB
testcase_24 AC 28 ms
4,348 KB
testcase_25 AC 28 ms
4,348 KB
testcase_26 AC 27 ms
4,348 KB
testcase_27 AC 31 ms
4,348 KB
testcase_28 AC 33 ms
4,348 KB
testcase_29 AC 32 ms
4,348 KB
testcase_30 AC 29 ms
4,348 KB
testcase_31 AC 26 ms
4,348 KB
testcase_32 AC 24 ms
4,348 KB
testcase_33 AC 27 ms
4,348 KB
testcase_34 AC 24 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 3 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 184 ms
7,328 KB
testcase_51 AC 184 ms
7,328 KB
testcase_52 AC 179 ms
7,328 KB
testcase_53 AC 176 ms
7,328 KB
testcase_54 AC 178 ms
7,328 KB
testcase_55 AC 182 ms
7,328 KB
testcase_56 AC 173 ms
7,064 KB
testcase_57 AC 161 ms
6,800 KB
testcase_58 AC 182 ms
7,328 KB
testcase_59 AC 185 ms
7,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define ALL(x) begin(x), end(x)
using namespace std;

/**
 * @sa https://oeis.org/A002187
 * @note > Has period 34 with the only exceptions at n=0, 14, 16, 17, 31, 34 and 51.
 */
vector<int> make_grundy(int k) {
    vector<int> grundy(k);
    grundy[0] = 0;
    REP3 (len, 1, k) {
        vector<int> used;
        used.push_back(grundy[max(0, len - 2)]);
        REP3 (l, 3, len + 1) {
            used.push_back(grundy[l - 3] ^ grundy[len - l]);
        }
        sort(ALL(used));
        used.erase(unique(ALL(used)), used.end());
        int g = 0;
        while (g < used.size() and g == used[g]) {
            ++ g;
        }
        grundy[len] = g;
    }
    return grundy;
}

bool solve(int n, vector<int> a) {
    vector<int> table = make_grundy(34 * 3);
    auto grundy = [&](int k) { return table[k < 34 * 3 ? k : k % 34 + 34 * 2]; };

    sort(ALL(a));
    a.erase(unique(ALL(a)), a.end());

    int sum_g = 0;
    for (int l = 0; l < a.size(); ) {
        int r = l + 1;
        while (r < a.size() and a[r] - a[l] == r - l) ++ r;
        sum_g ^= grundy(r - l);
        l = r;
    }
    return sum_g;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP (i, n) cin >> a[i];

    bool ans = solve(n, a);

    cout << (ans ? "First" : "Second") << endl;
    return 0;
}
0