結果
問題 |
No.942 プレゼント配り
|
ユーザー |
![]() |
提出日時 | 2020-01-23 22:58:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 1,286 bytes |
コンパイル時間 | 835 ms |
コンパイル使用メモリ | 75,904 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2024-07-21 19:07:03 |
合計ジャッジ時間 | 2,626 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { int N, K; cin >> N >> K; int p = N / K; if (p % 2 == 0) { cout << "Yes" << endl; for (int i = 0; i < K * (p / 2); i += p / 2) { for (int j = 0; j < p / 2; ++j) { if (j) cout << ' '; cout << i + j + 1; } for (int j = 0; j < p / 2; ++j) { cout << ' ' << N - i - j; } cout << endl; } } else if (K == 1) { cout << "Yes" << endl; for (int i = 0; i < N; ++i) { if (i) cout << ' '; cout << i + 1; } cout << endl; } else if (p == 1) { cout << "No" << endl; } else if (N % 2 == 0) { cout << "No" << endl; } else { vector<vector<int> > g(p); int lim = K * 3 / 2; for (int i = -lim; i <= lim; ++i) { if ((i > 0 ? i : -i) % 3 == 0) { g[0].push_back(i + N / 2); } else if (i < 0) { g[1].push_back(i + N / 2); } else { g[2].push_back(i + N / 2); } } reverse(g[0].begin(), g[0].end()); int t = (p - 3) / 2; for (int i = 0; i < t * K; ++i) { g[3 + i % t * 2].push_back(i); g[4 + i % t * 2].push_back(N - i - 1); } cout << "Yes" << endl; for (int i = 0; i < K; ++i) { for (int j = 0; j < p; ++j) { if (j) cout << ' '; cout << g[j][i] + 1; } cout << endl; } } return 0; }