結果

問題 No.942 プレゼント配り
ユーザー ianCKianCK
提出日時 2019-12-09 08:14:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 1,771 ms
コンパイル使用メモリ 40,940 KB
実行使用メモリ 8,508 KB
最終ジャッジ日時 2023-09-02 12:56:38
合計ジャッジ時間 2,478 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,620 KB
testcase_01 AC 23 ms
8,336 KB
testcase_02 AC 4 ms
7,676 KB
testcase_03 AC 4 ms
7,652 KB
testcase_04 AC 23 ms
8,496 KB
testcase_05 AC 23 ms
8,268 KB
testcase_06 AC 4 ms
7,640 KB
testcase_07 AC 4 ms
7,672 KB
testcase_08 AC 18 ms
8,416 KB
testcase_09 AC 22 ms
8,472 KB
testcase_10 AC 4 ms
7,652 KB
testcase_11 AC 4 ms
7,672 KB
testcase_12 AC 4 ms
7,640 KB
testcase_13 AC 5 ms
7,660 KB
testcase_14 AC 20 ms
8,224 KB
testcase_15 AC 15 ms
8,436 KB
testcase_16 AC 17 ms
8,508 KB
testcase_17 AC 17 ms
8,492 KB
testcase_18 AC 5 ms
7,712 KB
testcase_19 AC 4 ms
7,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
using namespace std;
constexpr int kN = int(2E5 + 10);
#define PB push_back
vector<int> ans[kN];

int main() {
	int n, k, need, now;
	scanf("%d%d", &n, &k);
	if (n == 1 && k == 1) {
		printf("Yes\n1\n");
		return 0;
	}
	if (n == k || (long long int) n * (long long int) (n + 1) % (k << 1) != 0) printf("No\n");
	else {
		need = n / k;
		now = 1;
		if (need & 1) {
			for (int i = 1; i <= k; i++) ans[i].PB(i);
			for (int i = 1, j = 0; i <= k; i++, j += 2) {
				if (j >= k) j -= k;
				ans[i].PB(k * 3 - j);
				ans[i].PB((k * 3 + 3) / 2 + j - i);
			}
			need -= 3;
			now = k * 3 + 1;
		}
		while (need) {
			for (int i = 1; i <= k; i++) ans[i].PB(now++);
			for (int i = k; i >= 1; i--) ans[i].PB(now++);
			need -= 2;
		}
		need = n / k;
		printf("Yes\n");
		for (int i = 1; i <= k; i++) {
			printf("%d", ans[i][0]);
			for (int j = 1; j < need; j++) printf(" %d", ans[i][j]);
			printf("\n");
		}
	}
}
0