結果

問題 No.1770 N言っちゃダメゲーム (6)
ユーザー ngtkanangtkana
提出日時 2020-06-11 01:47:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,466 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 209,648 KB
実行使用メモリ 14,096 KB
最終ジャッジ日時 2023-09-16 21:56:41
合計ジャッジ時間 4,438 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 25 ms
12,292 KB
testcase_11 AC 26 ms
12,444 KB
testcase_12 AC 27 ms
12,448 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 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 24 ms
12,080 KB
testcase_29 AC 13 ms
6,700 KB
testcase_30 AC 22 ms
11,152 KB
testcase_31 AC 12 ms
6,128 KB
testcase_32 AC 25 ms
13,708 KB
testcase_33 AC 30 ms
13,968 KB
testcase_34 AC 28 ms
13,988 KB
testcase_35 AC 29 ms
14,036 KB
testcase_36 AC 28 ms
13,900 KB
testcase_37 AC 28 ms
13,860 KB
testcase_38 AC 24 ms
13,988 KB
testcase_39 AC 25 ms
13,924 KB
testcase_40 AC 24 ms
13,916 KB
testcase_41 AC 24 ms
14,096 KB
testcase_42 AC 25 ms
13,900 KB
testcase_43 AC 25 ms
13,708 KB
testcase_44 AC 17 ms
9,956 KB
testcase_45 AC 25 ms
13,704 KB
testcase_46 AC 28 ms
13,912 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);

    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