結果
問題 | No.1974 2x2 Flipper |
ユーザー | 37zigen |
提出日時 | 2022-06-10 23:47:00 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,635 bytes |
コンパイル時間 | 2,478 ms |
コンパイル使用メモリ | 87,580 KB |
実行使用メモリ | 51,932 KB |
最終ジャッジ日時 | 2024-09-21 07:02:27 |
合計ジャッジ時間 | 12,624 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 150 ms
42,576 KB |
testcase_01 | AC | 227 ms
46,668 KB |
testcase_02 | AC | 215 ms
43,372 KB |
testcase_03 | AC | 299 ms
47,416 KB |
testcase_04 | AC | 318 ms
47,972 KB |
testcase_05 | AC | 264 ms
47,820 KB |
testcase_06 | AC | 294 ms
47,200 KB |
testcase_07 | AC | 312 ms
47,096 KB |
testcase_08 | AC | 237 ms
45,668 KB |
testcase_09 | AC | 320 ms
47,520 KB |
testcase_10 | WA | - |
testcase_11 | AC | 311 ms
47,556 KB |
testcase_12 | AC | 343 ms
47,312 KB |
testcase_13 | AC | 325 ms
47,432 KB |
testcase_14 | AC | 308 ms
47,348 KB |
testcase_15 | AC | 346 ms
47,332 KB |
testcase_16 | AC | 243 ms
47,176 KB |
testcase_17 | AC | 296 ms
47,484 KB |
testcase_18 | AC | 257 ms
46,620 KB |
testcase_19 | AC | 246 ms
46,520 KB |
testcase_20 | AC | 306 ms
47,204 KB |
testcase_21 | AC | 327 ms
47,668 KB |
testcase_22 | AC | 372 ms
47,512 KB |
testcase_23 | AC | 366 ms
47,592 KB |
testcase_24 | AC | 331 ms
51,932 KB |
testcase_25 | AC | 145 ms
42,932 KB |
ソースコード
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(); } }