結果

問題 No.307 最近色塗る問題多くない?
ユーザー htensaihtensai
提出日時 2020-05-12 19:03:31
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,607 bytes
コンパイル時間 3,014 ms
コンパイル使用メモリ 74,836 KB
実行使用メモリ 74,156 KB
最終ジャッジ日時 2023-10-11 21:33:19
合計ジャッジ時間 13,935 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
60,156 KB
testcase_01 AC 127 ms
56,080 KB
testcase_02 AC 130 ms
55,496 KB
testcase_03 AC 127 ms
55,236 KB
testcase_04 AC 200 ms
56,884 KB
testcase_05 AC 147 ms
56,004 KB
testcase_06 AC 146 ms
55,228 KB
testcase_07 AC 1,595 ms
68,892 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);
		    }
		}
		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;
	    }
	}
}
0