結果

問題 No.942 プレゼント配り
ユーザー bal4u
提出日時 2019-12-06 06:17:03
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,011 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 30,848 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 04:54:20
合計ジャッジ時間 2,411 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <stdio.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 main()
{
	int N, K, a, b, s, x, f;
	
	N = in(), K = in();
	if (K == 1) {
		outs("Yes");
		a = 1, x = N; while (--x) out(a++), pc(' ');
		out(N), pc('\n');
	} else {
		s = N/K;
		if ((s & 1) || (ll)N*(N+1)%(2*K)) outs("No");
		else {
			outs("Yes");
			a = 1, b = N, s = N/K;
			while (K--) {
				f = 1, x = s; while (--x) {
					if (f) out(a++), pc(' '), f = 0;
					else   out(b--), pc(' '), f = 1;
				}
				out(b--), pc('\n');
			}
		}
	}
	return 0;
}
0