結果

問題 No.307 最近色塗る問題多くない?
ユーザー tentententen
提出日時 2020-12-23 16:45:09
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,887 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 78,988 KB
実行使用メモリ 130,824 KB
最終ジャッジ日時 2023-10-21 15:13:00
合計ジャッジ時間 11,581 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
130,824 KB
testcase_01 AC 130 ms
57,532 KB
testcase_02 AC 130 ms
57,592 KB
testcase_03 AC 128 ms
57,388 KB
testcase_04 AC 198 ms
58,496 KB
testcase_05 AC 140 ms
57,596 KB
testcase_06 AC 144 ms
57,772 KB
testcase_07 AC 1,488 ms
73,704 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
            }
        }
        int q = sc.nextInt();
        ArrayDeque<Path> deq = new ArrayDeque<>();
        for (int i = 0; i < q; i++) {
            int r = sc.nextInt() - 1;
            int c = sc.nextInt() - 1;
            boolean color = (sc.nextInt() == 1);
            deq.add(new Path(r, c, color));
            while (deq.size() > 0) {
                Path p = deq.poll();
                if (p.r < 0 || p.r >= h || p.c < 0 || p.c >= w || field[p.r][p.c] == p.color) {
                    continue;
                }
                field[p.r][p.c] = p.color;
                deq.add(new Path(p.r - 1, p.c, p.color));
                deq.add(new Path(p.r + 1, p.c, p.color));
                deq.add(new Path(p.r, p.c - 1, p.color));
                deq.add(new Path(p.r, p.c + 1, p.color));
            }
        }
        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 r;
        int c;
        boolean color;
        
        public Path(int r, int c, boolean color) {
            this.r = r;
            this.c = c;
            this.color = color;
        }
    }
}
0