結果

問題 No.2112 All 2x2 are Equal
ユーザー CuriousFairy315CuriousFairy315
提出日時 2022-10-28 23:04:52
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,127 bytes
コンパイル時間 4,778 ms
コンパイル使用メモリ 74,876 KB
実行使用メモリ 123,780 KB
最終ジャッジ日時 2023-09-20 06:18:22
合計ジャッジ時間 13,038 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

	public Main() {
		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();
				}
			}
			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