結果
問題 |
No.307 最近色塗る問題多くない?
|
ユーザー |
![]() |
提出日時 | 2020-05-12 19:03:31 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,607 bytes |
コンパイル時間 | 3,191 ms |
コンパイル使用メモリ | 78,140 KB |
実行使用メモリ | 58,544 KB |
最終ジャッジ日時 | 2024-09-13 20:24:48 |
合計ジャッジ時間 | 11,354 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 TLE * 1 -- * 27 |
ソースコード
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]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { field[i][j] = (sc.nextInt() == 1); } } ArrayDeque<Path> deq = new ArrayDeque<>(); int q = sc.nextInt(); for (int i = 0; i < q; i++) { deq.add(new Path(sc.nextInt() - 1, sc.nextInt() - 1, 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; 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 (field[i][j]) { 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; } } }