結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー | htensai |
提出日時 | 2020-05-12 19:24:14 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,302 bytes |
コンパイル時間 | 2,392 ms |
コンパイル使用メモリ | 74,848 KB |
実行使用メモリ | 72,708 KB |
最終ジャッジ日時 | 2023-10-11 21:35:43 |
合計ジャッジ時間 | 23,838 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 126 ms
55,488 KB |
testcase_01 | WA | - |
testcase_02 | AC | 130 ms
55,476 KB |
testcase_03 | AC | 127 ms
55,452 KB |
testcase_04 | AC | 200 ms
58,272 KB |
testcase_05 | AC | 146 ms
55,524 KB |
testcase_06 | WA | - |
testcase_07 | AC | 345 ms
60,644 KB |
testcase_08 | AC | 610 ms
67,824 KB |
testcase_09 | AC | 410 ms
61,948 KB |
testcase_10 | AC | 272 ms
60,208 KB |
testcase_11 | AC | 372 ms
60,660 KB |
testcase_12 | AC | 135 ms
55,516 KB |
testcase_13 | AC | 554 ms
61,040 KB |
testcase_14 | AC | 229 ms
59,660 KB |
testcase_15 | AC | 245 ms
60,364 KB |
testcase_16 | AC | 238 ms
60,312 KB |
testcase_17 | AC | 417 ms
63,048 KB |
testcase_18 | AC | 762 ms
69,388 KB |
testcase_19 | AC | 702 ms
69,988 KB |
testcase_20 | AC | 208 ms
58,708 KB |
testcase_21 | AC | 620 ms
67,296 KB |
testcase_22 | AC | 592 ms
65,628 KB |
testcase_23 | AC | 1,849 ms
72,708 KB |
testcase_24 | AC | 887 ms
69,988 KB |
testcase_25 | AC | 1,227 ms
70,652 KB |
testcase_26 | AC | 1,908 ms
71,992 KB |
testcase_27 | AC | 538 ms
60,532 KB |
testcase_28 | AC | 687 ms
64,932 KB |
testcase_29 | AC | 506 ms
60,236 KB |
testcase_30 | AC | 1,541 ms
70,164 KB |
testcase_31 | AC | 694 ms
64,568 KB |
testcase_32 | AC | 639 ms
64,188 KB |
testcase_33 | AC | 360 ms
60,308 KB |
testcase_34 | AC | 652 ms
64,408 KB |
testcase_35 | AC | 647 ms
66,508 KB |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int w = sc.nextInt(); boolean[][] field = new boolean[h][w]; int tCount = 0; int fCount = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { field[i][j] = (sc.nextInt() == 1); if (field[i][j]) { tCount++; } else { fCount++; } } } ArrayDeque<Path> deq = new ArrayDeque<>(); int q = sc.nextInt(); boolean last = true; for (int i = 0; i < q; i++) { if (tCount > 0 && fCount > 0) { deq.add(new Path(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt() == 1)); } else { sc.nextInt(); sc.nextInt(); last = (sc.nextInt() == 1); } while (deq.size() > 0) { Path p = deq.poll(); if (p.row < 0 || p.row >= h || p.col < 0 || p.col >= w) { continue; } if (field[p.row][p.col] == p.type) { continue; } field[p.row][p.col] = p.type; if (p.type) { tCount++; fCount--; } else { tCount--; fCount++; } deq.add(new Path(p.row - 1, p.col, p.type)); deq.add(new Path(p.row + 1, p.col, p.type)); deq.add(new Path(p.row, p.col - 1, p.type)); deq.add(new Path(p.row, p.col + 1, p.type)); } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j > 0) { sb.append(" "); } if (tCount > 0 && fCount > 0) { if (field[i][j]) { sb.append("1"); } else { sb.append("0"); } } else { if (last) { sb.append("1"); } else { sb.append("0"); } } } sb.append("\n"); } System.out.print(sb); } static class Path { int row; int col; boolean type; public Path(int row, int col, boolean type) { this.row = row; this.col = col; this.type = type; } } }