結果

問題 No.1770 N言っちゃダメゲーム (6)
ユーザー ngtkanangtkana
提出日時 2020-06-11 01:49:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,511 bytes
コンパイル時間 2,057 ms
コンパイル使用メモリ 211,072 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2023-09-16 21:57:04
合計ジャッジ時間 4,082 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 25 ms
12,464 KB
testcase_11 AC 25 ms
12,248 KB
testcase_12 AC 25 ms
12,284 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 23 ms
12,296 KB
testcase_29 AC 12 ms
6,752 KB
testcase_30 AC 21 ms
11,036 KB
testcase_31 AC 11 ms
6,076 KB
testcase_32 AC 23 ms
13,812 KB
testcase_33 AC 28 ms
14,080 KB
testcase_34 AC 28 ms
13,940 KB
testcase_35 AC 26 ms
13,924 KB
testcase_36 AC 27 ms
13,944 KB
testcase_37 AC 25 ms
14,028 KB
testcase_38 AC 24 ms
13,960 KB
testcase_39 AC 24 ms
13,856 KB
testcase_40 AC 24 ms
14,052 KB
testcase_41 AC 23 ms
13,992 KB
testcase_42 AC 23 ms
14,080 KB
testcase_43 AC 23 ms
13,856 KB
testcase_44 AC 15 ms
9,968 KB
testcase_45 AC 22 ms
13,864 KB
testcase_46 AC 26 ms
13,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * validator
 */

#include <bits/stdc++.h>

std::pair<int, char> read() {
    int x = 0;
    char c;
    while (true) {
        c = std::getchar();
        if (!std::isdigit(c)) {
            return std::pair(x, c);
        }
        x = 10 * x + c - '0';
    }
}

int main() {
    char c;
    int n, k;
    std::tie(n, c) = read();
    assert(c == ' ');
    std::tie(k, c) = read();
    assert(c == '\n');
    assert(std::getchar() == EOF);
    assert(1 <= k && k < n && n <= 200'000);

    if (k==1) {
        std::cout << 1 << '\n';
        return 0;
    }

    std::vector<std::vector<int>> a(n+1);
    std::vector<int> b = {1};
    for (int i = 2; i <= n; i++) {
        auto&& v = a.at(i);
        int x = b.back();
        auto transite = [&](int j) {
            int d = i - j;
            if (d <= k && (a.at(j).empty()
                       || (a.at(j).size() == int{1} && a.at(j).front() == d)))
            {
                v.push_back(d);
            }
        };
        transite(x);
        transite((i + x) / 2);
        if (int{1} != b.size()) {
            int y = b.at(b.size() - 2);
            transite(y + k + 1);
            transite((i + y) / 2);
        }
        std::sort(v.begin(), v.end());
        v.resize(std::unique(v.begin(), v.end()) - v.begin()); if (v.empty()) b.push_back(i);
    }

    std::vector<int> ans = a.at(n);
    if (ans.empty()) {
        std::cout << 0 << '\n';
    } else {
        for (int x: ans) {
            std::cout << x << '\n';
        }
    }
}
0