結果

問題 No.883 ぬりえ
ユーザー ks2mks2m
提出日時 2019-09-13 21:45:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,991 ms / 2,000 ms
コード長 1,115 bytes
コンパイル時間 2,497 ms
コンパイル使用メモリ 74,440 KB
実行使用メモリ 67,328 KB
最終ジャッジ日時 2023-09-17 15:28:44
合計ジャッジ時間 9,640 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,196 KB
testcase_01 AC 128 ms
56,196 KB
testcase_02 AC 124 ms
55,668 KB
testcase_03 AC 126 ms
55,636 KB
testcase_04 AC 126 ms
57,840 KB
testcase_05 AC 123 ms
55,916 KB
testcase_06 AC 125 ms
55,640 KB
testcase_07 AC 127 ms
55,640 KB
testcase_08 AC 129 ms
55,976 KB
testcase_09 AC 126 ms
55,868 KB
testcase_10 AC 129 ms
56,000 KB
testcase_11 AC 133 ms
55,784 KB
testcase_12 AC 135 ms
56,180 KB
testcase_13 AC 134 ms
55,860 KB
testcase_14 AC 165 ms
56,160 KB
testcase_15 AC 1,991 ms
67,328 KB
testcase_16 AC 693 ms
65,432 KB
testcase_17 AC 672 ms
66,612 KB
testcase_18 AC 166 ms
56,304 KB
testcase_19 AC 161 ms
56,100 KB
testcase_20 AC 128 ms
56,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		int n2 = (int) Math.ceil(Math.sqrt(n));
		if (n2 <= k) {
			System.out.println(n2);
			int cnt = 0;
			for (int i = 0; i < n2; i++) {
				for (int j = 0; j < n2; j++) {
					if (cnt < n) {
						System.out.print('#');
						cnt++;
					} else {
						System.out.print('.');
					}
				}
				System.out.println();
			}
		} else {
			int m = (n + k - 1) / k;
			System.out.println(m);
			char[][] a = new char[m][m];
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < m; j++) {
					a[i][j] = '.';
				}
			}
			int cnt = 0;
			label:
			for (int i = 0; i < m; i++) {
				int x = i;
				for (int j = 0; j < m; j++) {
					a[j][x] = '#';
					cnt++;
					if (cnt == n) {
						break label;
					}
					x++;
					if (x == m) {
						x = 0;
					}
				}
			}
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < m; j++) {
					System.out.print(a[i][j]);
				}
				System.out.println();
			}
		}
	}
}
0