結果

問題 No.2112 All 2x2 are Equal
ユーザー CuriousFairy315CuriousFairy315
提出日時 2022-10-28 23:07:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,226 ms / 2,000 ms
コード長 1,210 bytes
コンパイル時間 2,401 ms
コンパイル使用メモリ 75,456 KB
実行使用メモリ 152,400 KB
最終ジャッジ日時 2023-09-20 06:22:31
合計ジャッジ時間 28,592 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,804 KB
testcase_01 AC 127 ms
55,800 KB
testcase_02 AC 238 ms
57,184 KB
testcase_03 AC 237 ms
44,716 KB
testcase_04 AC 666 ms
70,208 KB
testcase_05 AC 770 ms
98,824 KB
testcase_06 AC 1,020 ms
105,380 KB
testcase_07 AC 615 ms
78,448 KB
testcase_08 AC 918 ms
103,448 KB
testcase_09 AC 292 ms
59,256 KB
testcase_10 AC 634 ms
69,308 KB
testcase_11 AC 551 ms
71,848 KB
testcase_12 AC 573 ms
60,640 KB
testcase_13 AC 966 ms
103,236 KB
testcase_14 AC 267 ms
59,096 KB
testcase_15 AC 800 ms
87,732 KB
testcase_16 AC 166 ms
54,124 KB
testcase_17 AC 940 ms
105,812 KB
testcase_18 AC 233 ms
57,728 KB
testcase_19 AC 305 ms
47,532 KB
testcase_20 AC 233 ms
43,728 KB
testcase_21 AC 895 ms
103,556 KB
testcase_22 AC 266 ms
56,896 KB
testcase_23 AC 238 ms
45,272 KB
testcase_24 AC 344 ms
47,796 KB
testcase_25 AC 420 ms
56,524 KB
testcase_26 AC 343 ms
48,164 KB
testcase_27 AC 499 ms
59,368 KB
testcase_28 AC 744 ms
85,404 KB
testcase_29 AC 299 ms
59,008 KB
testcase_30 AC 594 ms
67,240 KB
testcase_31 AC 791 ms
88,332 KB
testcase_32 AC 1,226 ms
149,392 KB
testcase_33 AC 1,190 ms
152,400 KB
testcase_34 AC 1,154 ms
150,472 KB
testcase_35 AC 1,171 ms
150,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import static java.lang.System.err;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) {
		java.io.PrintWriter out = new java.io.PrintWriter(System.out);
		new Main(out);
		out.flush();
		err.flush();
	}

	public Main(java.io.PrintWriter out) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			int H = sc.nextInt(), W = sc.nextInt();
			int[][] grid = new int[H][W];
			TreeSet<Integer> use = new TreeSet<>();
			for (int i = 1; i <= H * W; ++i) use.add(i);
			for (int y = 0; y < H; ++y) {
				for (int x = 0; x < W; ++x) {
					grid[y][x] = (y + x) % 2 == 0 ? use.pollFirst() : use.pollLast();
				}
			}
			out.println("Yes");
			for (int y = 0; y < H; ++y) {
				out.print(grid[y][0]);
				for (int x = 1; x < W; ++x) {
					out.print(' ');
					out.print(grid[y][x]);
				}
				out.println();
			}
			check(grid);
		}
	}

	private void check(int[][] grid) {
		int H = grid.length, W = grid[0].length;
		int S = grid[0][0] + grid[0][1] + grid[1][0] + grid[1][1];
		for (int y = 1; y < H; ++y) {
			for (int x = 1; x < W; ++x) {
				if (grid[y - 1][x - 1] + grid[y][x - 1] + grid[y - 1][x] + grid[y][x] != S) throw new AssertionError();
			}
		}
	}
}
0