結果

問題 No.1974 2x2 Flipper
ユーザー ks2mks2m
提出日時 2022-06-10 22:50:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,138 bytes
コンパイル時間 3,177 ms
コンパイル使用メモリ 78,024 KB
実行使用メモリ 61,468 KB
最終ジャッジ日時 2023-10-21 06:00:25
合計ジャッジ時間 10,034 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,604 KB
testcase_01 AC 113 ms
55,556 KB
testcase_02 AC 58 ms
53,664 KB
testcase_03 AC 203 ms
60,980 KB
testcase_04 AC 161 ms
57,900 KB
testcase_05 AC 128 ms
57,764 KB
testcase_06 AC 181 ms
58,428 KB
testcase_07 AC 166 ms
58,544 KB
testcase_08 AC 104 ms
55,612 KB
testcase_09 AC 184 ms
58,620 KB
testcase_10 AC 111 ms
55,408 KB
testcase_11 AC 166 ms
58,216 KB
testcase_12 AC 194 ms
61,064 KB
testcase_13 AC 186 ms
58,336 KB
testcase_14 AC 132 ms
57,796 KB
testcase_15 AC 194 ms
61,040 KB
testcase_16 AC 101 ms
55,244 KB
testcase_17 AC 188 ms
60,656 KB
testcase_18 AC 93 ms
54,500 KB
testcase_19 AC 105 ms
55,592 KB
testcase_20 AC 146 ms
57,732 KB
testcase_21 AC 192 ms
61,388 KB
testcase_22 AC 195 ms
61,308 KB
testcase_23 AC 206 ms
61,468 KB
testcase_24 AC 203 ms
61,372 KB
testcase_25 AC 50 ms
53,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int h = Integer.parseInt(sa[0]);
		int w = Integer.parseInt(sa[1]);
		br.close();

		int ans = h * w;
		int[][] a = new int[h][w];
		for (int i = 0; i < h; i++) {
			Arrays.fill(a[i], 1);
		}
		if (h % 2 == 0) {
			if (w % 2 == 0) {
			} else {
				ans -= h;
				for (int i = 0; i < h; i++) {
					a[i][w - 1] = 0;
				}
			}
		} else {
			if (w % 2 == 0) {
				ans -= w;
				Arrays.fill(a[h - 1], 0);
			} else {
				ans -= Math.max(h, w);
				for (int i = 0; i < h; i++) {
					a[i][Math.min(i, w - 1)] = 0;
				}
				for (int i = h; i < w; i++) {
					a[h - 1][i] = 0;
				}
			}
		}

		System.out.println(ans);
		for (int i = 0; i < h; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j = 0; j < w; j++) {
				sb.append(a[i][j]).append(' ');
			}
			sb.deleteCharAt(sb.length() - 1);
			System.out.println(sb.toString());
		}
	}
}
0