結果

問題 No.942 プレゼント配り
ユーザー MisterMister
提出日時 2020-08-04 17:48:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,260 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 80,620 KB
実行使用メモリ 7,704 KB
最終ジャッジ日時 2023-10-12 21:19:42
合計ジャッジ時間 2,906 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 18 ms
4,352 KB
testcase_02 AC 5 ms
7,704 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 17 ms
4,348 KB
testcase_05 AC 17 ms
4,356 KB
testcase_06 AC 4 ms
7,692 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 13 ms
4,352 KB
testcase_09 AC 15 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void solve() {
    int n, k;
    std::cin >> n >> k;
    int m = n / k;

    std::vector<std::vector<int>> ans(k);

    auto turn = [&]() {
        for (int i = 0; i < k; ++i) {
            ans[i].push_back(n--);
        }
        for (int i = k - 1; i >= 0; --i) {
            ans[i].push_back(n--);
        }
        m -= 2;
    };

    if (m % 2 == 0) {
        while (n > 0) turn();

    } else if (k % 2 == 0) {
        std::cout << "No\n";
        return;

    } else if (m == 1) {
        if (k > 1) {
            std::cout << "No\n";
            return;
        }
        ans[0].push_back(1);

    } else {
        while (m > 3) turn();

        int d = k / 2;
        for (int i = 0; i < k; ++i) {
            ans[i].push_back(n--);
        }
        for (int i = 0; i < k; ++i) {
            ans[(d + i) % k].push_back(n--);
        }
        for (int i = 0; i < k; ++i) {
            ans[(d + i) * 2 % k].push_back(n--);
        }
    }

    std::cout << "Yes\n";
    for (const auto& v : ans) {
        for (auto x : v) std::cout << x << " ";
        std::cout << "\n";
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0