結果

問題 No.1770 N言っちゃダメゲーム (6)
ユーザー trineutrontrineutron
提出日時 2020-06-02 18:56:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,365 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 82,760 KB
実行使用メモリ 4,616 KB
最終ジャッジ日時 2023-09-16 21:56:33
合計ジャッジ時間 2,717 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 10 ms
4,380 KB
testcase_11 AC 11 ms
4,376 KB
testcase_12 AC 11 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 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 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 13 ms
4,380 KB
testcase_29 AC 6 ms
4,376 KB
testcase_30 AC 10 ms
4,376 KB
testcase_31 AC 5 ms
4,376 KB
testcase_32 AC 13 ms
4,376 KB
testcase_33 AC 14 ms
4,380 KB
testcase_34 AC 15 ms
4,380 KB
testcase_35 AC 14 ms
4,380 KB
testcase_36 AC 14 ms
4,376 KB
testcase_37 AC 13 ms
4,384 KB
testcase_38 AC 14 ms
4,560 KB
testcase_39 AC 13 ms
4,616 KB
testcase_40 AC 13 ms
4,508 KB
testcase_41 AC 13 ms
4,540 KB
testcase_42 AC 14 ms
4,540 KB
testcase_43 AC 14 ms
4,376 KB
testcase_44 AC 9 ms
4,380 KB
testcase_45 AC 13 ms
4,376 KB
testcase_46 AC 14 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

int main() {
    int n, k;
    std::cin >> n >> k;
    assert(1 <= k and k < n and n <= 200000);
    if (k == 1) {
        std::cout << 1 << std::endl;
        return 0;
    }
    int a0 = n - 1, a1 = n + 2 * k;
    std::vector<int> dp(n + k); // -1: declarer win, 0: declarer lose
    dp.at(n - 1) = -1;
    for (int i = n - 2; i >= 0; i--) {
        int d0 = (a0 - i) / 2, d1 = (a1 - i) / 2, d2 = (k + 1) / 2;
        std::vector<int> w;
        if (a0 <= i + k) w.push_back(a0 - i);
        if ((i + a0) % 2 == 0 and d0 <= k and dp.at(i + d0) == d0) w.push_back(d0);
        if ((i + a1) % 2 == 0 and d1 <= k and dp.at(i + d1) == d1) w.push_back(d1);
        if ((k + 1) % 2 == 0 and dp.at(i + d2) == d2) w.push_back(d2);
        std::sort(w.begin(), w.end());
        decltype(w)::iterator r = std::unique(w.begin(), w.end());
        w.erase(r, w.end());
        if (i == 0) {
            if (w.size() == 0) {
                std::cout << 0 << std::endl;
            } else {
                for (int x : w) {
                    std::cout << x << std::endl;
                }
            }
        } else if (w.size() == 0) {
            dp.at(i) = -1;
            a1 = a0;
            a0 = i;
        } else if (w.size() == 1) {
            dp.at(i) = w.at(0);
        }
    }
}
0