結果
問題 | No.715 集合と二人ゲーム |
ユーザー | startcpp |
提出日時 | 2018-07-17 00:19:34 |
言語 | C++11 (gcc 11.4.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,377 bytes |
コンパイル時間 | 940 ms |
コンパイル使用メモリ | 67,660 KB |
実行使用メモリ | 817,664 KB |
最終ジャッジ日時 | 2024-05-01 20:24:32 |
合計ジャッジ時間 | 4,201 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,376 KB |
testcase_01 | MLE | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
ソースコード
//実験的な解法。証明はしていない。 //とりあえず{1,2,3,…,n}のgrundy数をgrundy(n)として、grundy(1)~grundy(n)をO(n^2)で求めるところまでは典型。 //grundy数の種類が10種類と少ないことを利用して、grundy数 = iの出現位置を、i=0,1,2,…について求めてみる。 //そして、grundy(0), grundy(1), …を眺めていると、隣り合う出現位置の差が重要っぽいと思うので、↑の階差を取ってみる。 //すると、途中から周期的になっていることに気付く。ただしその周期は複雑で、iの値によってまちまちである。 //そこで、「1周期」を取り出してみる。例えば、grundy数 = i(i = 0)の出現位置の階差の周期は{4, 12, 4, 4, 10}である。 //そして、「1周期分」の和を取ってみる。4 + 12 + 4 + 4 + 10 = 34のように。すると、どのiについてもこれが34になっていることが分かる。 //よって、ある大きな整数Mを取ってくると、M以上のx全てについて、grundy(x) = grundy(x + 34)が成立することが分かる。 //これは、周期の開始位置を見る限り、M >= 85に設定すればOK.よって、O(M^2 + N)でこの問題は解けた。 #include <iostream> #include <algorithm> #include <vector> using namespace std; int n; int a[500000]; vector<int> nums; int dp[500001]; int grundy(int x) { if (x >= 85) { return dp[x] = grundy(85 + (x - 85) % 34); } if (x == 0) return 0; if (x <= 2) return 1; if (dp[x] != -1) return dp[x]; vector<int> gs; gs.push_back(grundy(x - 2)); for (int i = 0; i + 3 <= x; i++) { int g = grundy(i) ^ grundy(x - i - 3); gs.push_back(g); } sort(gs.begin(), gs.end()); for (int i = 0; ; i++) { int pos = lower_bound(gs.begin(), gs.end(), i) - gs.begin(); if (pos == gs.size() || gs[pos] > i) { return dp[x] = i; } } return -1; } int main() { int i; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int len = 1; for (i = 1; i < n; i++) { if (a[i] >= a[i - 1] + 2) { nums.push_back(len); len = 1; } else { len++; } } nums.push_back(len); for (i = 0; i < 500001; i++) dp[i] = -1; int g = 0; for (i = 0; i < nums.size(); i++) g ^= grundy(nums[i]); if (g == 0) cout << "Second" << endl; else cout << "First" << endl; return 0; }