結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー | nCk_cv |
提出日時 | 2015-11-27 23:48:04 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,754 bytes |
コンパイル時間 | 4,939 ms |
コンパイル使用メモリ | 76,960 KB |
実行使用メモリ | 66,912 KB |
最終ジャッジ日時 | 2023-10-12 01:35:26 |
合計ジャッジ時間 | 12,295 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 143 ms
56,064 KB |
testcase_01 | AC | 144 ms
56,084 KB |
testcase_02 | AC | 147 ms
56,056 KB |
testcase_03 | AC | 143 ms
55,668 KB |
testcase_04 | AC | 268 ms
59,968 KB |
testcase_05 | AC | 167 ms
56,024 KB |
testcase_06 | AC | 185 ms
56,484 KB |
testcase_07 | AC | 2,130 ms
66,912 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 | -- | - |
ソースコード
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++; } } id = 1; dfs(0,0,map,color,0,0,new boolean[h][w]); int I = 0; int J = 1; for(int i = I; i < h; i++) { for(int j = J; j < w; j++) { if(color[i][j] != id) dfs(i,j,map,color,i,j,new boolean[h][w]); } J = 0; } 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; dfs(ty,tx,MAP,COLOR,oa,ob,al); } } }