結果

問題 No.942 プレゼント配り
ユーザー t33f
提出日時 2019-12-28 18:32:18
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 71,416 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 08:26:24
合計ジャッジ時間 2,316 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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