結果

問題 No.307 最近色塗る問題多くない?
ユーザー nCk_cvnCk_cv
提出日時 2015-11-29 16:02:45
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,763 bytes
コンパイル時間 2,895 ms
コンパイル使用メモリ 85,756 KB
実行使用メモリ 69,648 KB
最終ジャッジ日時 2023-10-12 05:39:33
合計ジャッジ時間 29,503 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
56,088 KB
testcase_01 WA -
testcase_02 RE -
testcase_03 AC 137 ms
55,860 KB
testcase_04 WA -
testcase_05 RE -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 1,008 ms
67,392 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 RE -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 WA -
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.Map.Entry;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
      
      
public class Main {	

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] map = new char[h][w];
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				map[i][j] = sc.next().charAt(0);
			}
		}
		int[][] color = new int[h][w];
		int id = 0;
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				color[i][j] = id++;
			}
		}
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				dfs(i,j,map,color,i,j,new boolean[h][w]);
			}
		}
		int q = sc.nextInt();
		for(int i = 0; i < q; i++) {
			int r = sc.nextInt()-1;
			int c = sc.nextInt()-1;
			char x = sc.next().charAt(0);
			
			int target = color[r][c];
			
			for(int j = 0; j < h; j++) {
				for(int k = 0; k < w; k++) {
					if(color[j][k] == target)
					map[j][k] = x;
				}
			}
			dfs(r,c,map,color,r,c,new boolean[h][w]);
		}
		for(int i = 0; i < h; i++) {
			System.out.print(map[i][0]);
			for(int j = 1; j < w; j++) {
				System.out.print(" " + map[i][j]);
			}
			System.out.println();
		}
	}
	static int[] vx = {0,1,0,-1};
	static int[] vy = {1,0,-1,0};
	static void dfs(int a, int b, char[][] MAP, int[][] COLOR, int oa, int ob, boolean[][] al) {
		if(a < 0 || b < 0 || a >= MAP.length || b >= MAP[a].length || MAP[a][b] != MAP[oa][ob] || al[a][b]) return;
		COLOR[a][b] = COLOR[oa][ob];
		al[a][b] = true;
		for(int i = 0; i < 4; i++) {
			int ty = vy[i] + a;
			int tx = vx[i] + b;
			if(ty < 0 || tx < 0 || ty >= MAP.length || tx >= MAP[tx].length || MAP[ty][tx] != MAP[oa][ob] || al[ty][tx]) return;
			dfs(ty,tx,MAP,COLOR,oa,ob,al);
		}
	}
	
	
}
0