結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー | htensai |
提出日時 | 2020-05-12 19:25:29 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,872 ms / 4,000 ms |
コード長 | 2,327 bytes |
コンパイル時間 | 4,171 ms |
コンパイル使用メモリ | 74,720 KB |
実行使用メモリ | 72,268 KB |
最終ジャッジ日時 | 2023-10-11 21:34:49 |
合計ジャッジ時間 | 25,131 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 127 ms
55,440 KB |
testcase_01 | AC | 128 ms
55,760 KB |
testcase_02 | AC | 129 ms
55,840 KB |
testcase_03 | AC | 127 ms
55,588 KB |
testcase_04 | AC | 200 ms
60,808 KB |
testcase_05 | AC | 145 ms
55,848 KB |
testcase_06 | AC | 146 ms
55,660 KB |
testcase_07 | AC | 322 ms
60,520 KB |
testcase_08 | AC | 598 ms
67,672 KB |
testcase_09 | AC | 377 ms
62,464 KB |
testcase_10 | AC | 266 ms
62,076 KB |
testcase_11 | AC | 372 ms
58,676 KB |
testcase_12 | AC | 139 ms
55,652 KB |
testcase_13 | AC | 541 ms
61,280 KB |
testcase_14 | AC | 229 ms
59,408 KB |
testcase_15 | AC | 246 ms
60,700 KB |
testcase_16 | AC | 237 ms
59,812 KB |
testcase_17 | AC | 422 ms
63,592 KB |
testcase_18 | AC | 745 ms
69,972 KB |
testcase_19 | AC | 696 ms
70,380 KB |
testcase_20 | AC | 198 ms
58,340 KB |
testcase_21 | AC | 610 ms
67,276 KB |
testcase_22 | AC | 589 ms
68,240 KB |
testcase_23 | AC | 1,664 ms
71,576 KB |
testcase_24 | AC | 859 ms
70,116 KB |
testcase_25 | AC | 1,188 ms
70,688 KB |
testcase_26 | AC | 1,872 ms
69,688 KB |
testcase_27 | AC | 502 ms
60,832 KB |
testcase_28 | AC | 702 ms
64,812 KB |
testcase_29 | AC | 477 ms
60,508 KB |
testcase_30 | AC | 1,506 ms
72,268 KB |
testcase_31 | AC | 648 ms
69,992 KB |
testcase_32 | AC | 647 ms
64,456 KB |
testcase_33 | AC | 360 ms
60,692 KB |
testcase_34 | AC | 638 ms
64,456 KB |
testcase_35 | AC | 640 ms
64,356 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; last = 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; } } }