結果
問題 | No.2112 All 2x2 are Equal |
ユーザー |
![]() |
提出日時 | 2022-10-28 23:07:37 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,211 ms / 2,000 ms |
コード長 | 1,210 bytes |
コンパイル時間 | 2,417 ms |
コンパイル使用メモリ | 79,240 KB |
実行使用メモリ | 152,772 KB |
最終ジャッジ日時 | 2024-07-06 02:22:12 |
合計ジャッジ時間 | 27,215 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 34 |
ソースコード
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(); } } } }