結果
問題 |
No.8 N言っちゃダメゲーム
|
ユーザー |
![]() |
提出日時 | 2016-04-20 20:35:30 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 925 bytes |
コンパイル時間 | 603 ms |
コンパイル使用メモリ | 69,964 KB |
実行使用メモリ | 10,660 KB |
最終ジャッジ日時 | 2024-10-04 14:29:02 |
合計ジャッジ時間 | 7,011 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 TLE * 1 -- * 7 |
ソースコード
#include <algorithm> #include <cstdlib> #include <iostream> #include <set> #include <vector> constexpr int UNDEF = -1; // Based on http://solorab.net/blog/2015/12/19/srm-676-med/ int mex(std::set<int> const& s) { int m = 0; for (auto x : s) { if (x == m) { m++; } else { break; } } return m; } int compute_grundy_number(int n, int k) { std::vector<int> gs; gs = std::vector<int>(n, UNDEF); gs[n - 1] = 0; for (auto i = n - 2; i >= 0; i--) { std::set<int> next_gs; for (auto j = i + 1; j <= std::min(n - 1, i + k); j++) { next_gs.insert(gs[j]); } gs[i] = mex(next_gs); } return gs[0]; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int p; std::cin >> p; for (auto i = 0; i < p; i++) { int n, k; std::cin >> n >> k; int g; g = compute_grundy_number(n, k); std::cout << (g != 0 ? "Win" : "Lose") << std::endl; } return EXIT_SUCCESS; }