結果

問題 No.2112 All 2x2 are Equal
ユーザー CuriousFairy315
提出日時 2022-10-28 23:04:52
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,127 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 79,232 KB
実行使用メモリ 127,700 KB
最終ジャッジ日時 2024-07-06 02:18:09
合計ジャッジ時間 12,617 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 2
other WA * 2 TLE * 3 -- * 29
権限があれば一括ダウンロードができます

ソースコード

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