結果

問題 No.942 プレゼント配り
ユーザー t33ft33f
提出日時 2019-12-28 18:32:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 71,680 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 13:01:49
合計ジャッジ時間 2,144 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 16 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 17 ms
5,376 KB
testcase_05 AC 19 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 12 ms
5,376 KB
testcase_09 AC 14 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 14 ms
5,376 KB
testcase_15 AC 10 ms
5,376 KB
testcase_16 AC 12 ms
5,376 KB
testcase_17 AC 11 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <numeric>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int k, n; cin >> n >> k;
    if (k == n) {
        if (n == 1) cout << "Yes\n1\n";
        else cout << "No\n";
        return 0;
    }
    int d = n/k;
    if (k % 2 == 0 && d % 2 == 1) { cout << "No\n"; return 0; }
    vector<int> ans[k];
    if (d % 2 == 1) {
        int offset = (d-3)*k;
        d -= 3;
        for (int x = 1, y = (k+1)/2, z = k; x <= k; ) {
            ans[x-1].emplace_back(offset+x);
            ans[x-1].emplace_back(offset+k+y);
            ans[x-1].emplace_back(offset+2*k+z);
            x++; y++; z -= 2;
            if (y > k) { y -= k; z += k; }
        }
    }
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < d/2; j++) ans[i].emplace_back(k*j+i+1);
        for (int j = d/2; j < d; j++) ans[i].emplace_back(k*j+k-i);
    }
    cout << "Yes\n";
    for (int i = 0; i < k; i++) {
        for (int x : ans[i]) cout << x << ' ';
        cout << endl;
    }
}
0