結果

問題 No.1974 2x2 Flipper
ユーザー 37zigen37zigen
提出日時 2022-06-10 23:47:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 3,635 bytes
コンパイル時間 2,992 ms
コンパイル使用メモリ 84,620 KB
実行使用メモリ 66,048 KB
最終ジャッジ日時 2023-10-21 05:52:44
合計ジャッジ時間 12,932 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
60,176 KB
testcase_01 AC 215 ms
63,444 KB
testcase_02 AC 209 ms
61,120 KB
testcase_03 AC 289 ms
62,912 KB
testcase_04 AC 301 ms
63,476 KB
testcase_05 AC 259 ms
63,464 KB
testcase_06 AC 282 ms
63,708 KB
testcase_07 AC 302 ms
63,472 KB
testcase_08 AC 264 ms
63,244 KB
testcase_09 AC 324 ms
63,476 KB
testcase_10 WA -
testcase_11 AC 301 ms
63,476 KB
testcase_12 AC 314 ms
61,724 KB
testcase_13 AC 305 ms
63,476 KB
testcase_14 AC 299 ms
63,476 KB
testcase_15 AC 329 ms
61,540 KB
testcase_16 AC 239 ms
63,512 KB
testcase_17 AC 290 ms
63,708 KB
testcase_18 AC 246 ms
63,580 KB
testcase_19 AC 240 ms
63,584 KB
testcase_20 AC 301 ms
63,476 KB
testcase_21 AC 302 ms
64,144 KB
testcase_22 AC 358 ms
61,540 KB
testcase_23 AC 352 ms
63,476 KB
testcase_24 AC 330 ms
66,048 KB
testcase_25 AC 148 ms
58,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main implements Runnable {

	public static void main(String[] args) throws IOException {
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start();
	}
	
	public void run() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int H=sc.nextInt();
		int W=sc.nextInt();
		if (H%2==0&&W%2==0) {
			pw.println(H*W);
			for (int i=0;i<H;++i) {
				for (int j=0;j<W;++j) {
					pw.print(1+(j==W-1?"\n":" "));
				}
			}
		} else if (H%2==1&&W%2==1) {
			pw.println((H*W-Math.max(H, W)));
			int[][] a=new int[H][W];
			int m=Math.min(H, W);
			for (int i=0;i<H;++i) for (int j=0;j<W;++j) a[i][j]=1;
			for (int diag=0;diag<Math.max(H, W);++diag) {
				int i=diag%H;
				int j=diag%W;
				a[i][j]=0;
			}
			if (W > H) {
				if (W%m%2==0) {
					for (int i=0;i<H;++i) {
						for (int j=W/m*m;j<W;++j) {
							a[i][j]=(i==H-1?0:1);
						}
					}
				} else {
					if (W%m==1) {
						for (int i=0;i<H;++i) a[i][W-1]=0;
					}
				}
			} else if (W < H) {
				if (H%m%2==0) {
					for (int i=H/m*m;i<H;++i) {
						for (int j=0;j<W;++j) {
							a[i][j]=(j==W-1?0:1);
						}
					}
				} else {
					if (H%m==1) {
						for (int j=0;j<W;++j) a[H-1][j]=0;
					}
				}
			}
			for (int i=0;i<H;++i) {
				for (int j=0;j<W;++j) {
					pw.print(a[i][j]+(j==W-1?"\n":" "));
				}
			}
		} else if (H%2==0 && W%2==1) {
			pw.println((H*W-H));
			for (int i=0;i<H;++i) {
				for (int j=0;j<W;++j) {
					int v=1;
					if (j==W-1) v=0;
					pw.print(v+(j==W-1?"\n":" "));
				}
			}
		} else {
			pw.println((H*W-W));
			for (int i=0;i<H;++i) {
				for (int j=0;j<W;++j) {
					int v=1;
					if (i==H-1) v=0;
					pw.print(v+(j==W-1?"\n":" "));
				}
			}
		}
		pw.close();
	}

	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}
}
0