結果

問題 No.883 ぬりえ
ユーザー bal4ubal4u
提出日時 2019-09-14 20:10:01
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,366 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 31,360 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 17:28:26
合計ジャッジ時間 2,057 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder 883 ぬりえ
// 2019.9.14 bal4u

#include <stdio.h>
#include <string.h>
#include <math.h>

#if 1
int getchar_unlocked(void);
int putchar_unlocked(int c);
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

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

void out(int n) { // 非負整数の表示(出力)
	int i; char b[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}
void outs(char *s) { while (*s) pc(*s++); pc('\n'); }

int N, K, M;
char A[1003][1003];

int mi(int n) { int a = (int)sqrt((double)n); if (a*a < n) a++; return a; }

int spa(int n, int k, int s) {
	int r, c, m;
	if (k*k >= n || k*(k+1) < n) return 0;
	m = k+1;
	for (r = 0; r < m && n; r++) for (c = 0; c < m && n; c++) {
		if (c != m-r-1) A[s+r][s+c] = '#', n--;
	}
	return m;
}
		
int main()
{
	int r, c;
	
	N = in(), K = in();
	memset(A, '.', sizeof(A));
	M = 0; while (N) {
		if (K*K > N) K = mi(N);
		if ((r = spa(N, K, M)) > 0) M += r, N = 0;
		else {
			for (r = 0; r < K && N; r++) for (c = 0; c < K && N; c++) {
				A[M+r][M+c] = '#', N--;
			}
			M += K;
		}
	}
	out(M);
	for (r = 0; r < M; r++) A[r][M] = 0, outs(A[r]);
	return 0;
}
0