結果

問題 No.942 プレゼント配り
ユーザー bal4ubal4u
提出日時 2019-12-08 16:08:11
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,722 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 31,720 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-29 00:02:43
合計ジャッジ時間 2,552 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yuki 942 プレゼント配り
// 2019.12.8 bal4u

#include <stdio.h>
#include <stdlib.h>

typedef long long ll;

int getchar_unlocked(void);
int putchar_unlocked(int c);
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 非負整数の表示(出力)
	int i = 0; char b[30];
	while (n) b[i++] = n % 10 + '0', n /= 10;
	while (i--) pc(b[i]);
}

void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
int *ans[200002];

int main()
{
	int i, j, k, N, K, a;
	
	N = in(), K = in();
	if (K == 1) {
		outs("Yes");
		a = 0; while (--N) out(++a), pc(' ');
		out(++a), pc('\n');
		return 0;
	}
	if (N == K) { outs("No"); return 0; }
	int s = N/K;
	for (i = 0; i < K; ++i) ans[i] = malloc(s*sizeof(int));
	if (s & 1) {
		if (K & 1) {
			a = 0, k = s-3;
			for (j = 0; j < k; ++j) {
				for (i = 0; i < K; ++i) ans[i][j] = ++a;
				if (++j >= k) break;
				for (i = K-1; i >= 0; --i) ans[i][j] = ++a;
			}
			ll x = 0; for (j = 0; j < k; ++j) x += ans[0][j];
			x = (ll)N*(N+1)/(2*K) - x;
			for (i = 0; i < K; ++i) ans[i][k] = ++a;
			j = s-2, k = K/2+1;
			for (i = 0; i < K; ++i) {
				if (k == K) k = 0;
				ans[k++][j] = ++a;
			}
			++j;
			for (i = 0; i < K; ++i) {
				ans[i][j] = (int)(x-(ans[i][j-2]+ans[i][j-1]));
			}
		} else { outs("No"); return 0; }
	} else {
		a = 0, j = 0;
		while (j < s) {
			for (i = 0; i < K; ++i) ans[i][j] = ++a;
			++j;
			for (i = K-1; i >= 0; --i) ans[i][j] = ++a;
			++j;
		}
	}

	outs("Yes");
	for (i = 0; i < K; ++i) {
		out(ans[i][0]);
		for (j = 1; j < s; ++j) pc(' '), out(ans[i][j]);
		pc('\n');
	}
	return 0;
}
0