結果
問題 | No.2946 Puyo |
ユーザー | tenten |
提出日時 | 2024-10-28 09:23:58 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 354 ms / 2,000 ms |
コード長 | 2,901 bytes |
コンパイル時間 | 2,542 ms |
コンパイル使用メモリ | 78,992 KB |
実行使用メモリ | 66,448 KB |
最終ジャッジ日時 | 2024-10-28 09:24:17 |
合計ジャッジ時間 | 16,812 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 62 ms
50,480 KB |
testcase_01 | AC | 63 ms
50,864 KB |
testcase_02 | AC | 63 ms
50,740 KB |
testcase_03 | AC | 354 ms
66,448 KB |
testcase_04 | AC | 313 ms
66,008 KB |
testcase_05 | AC | 330 ms
66,208 KB |
testcase_06 | AC | 327 ms
66,320 KB |
testcase_07 | AC | 328 ms
65,900 KB |
testcase_08 | AC | 121 ms
52,628 KB |
testcase_09 | AC | 187 ms
58,400 KB |
testcase_10 | AC | 127 ms
52,412 KB |
testcase_11 | AC | 242 ms
60,828 KB |
testcase_12 | AC | 131 ms
52,600 KB |
testcase_13 | AC | 67 ms
50,912 KB |
testcase_14 | AC | 146 ms
54,816 KB |
testcase_15 | AC | 120 ms
52,092 KB |
testcase_16 | AC | 168 ms
54,632 KB |
testcase_17 | AC | 265 ms
60,548 KB |
testcase_18 | AC | 73 ms
50,956 KB |
testcase_19 | AC | 194 ms
55,524 KB |
testcase_20 | AC | 202 ms
58,492 KB |
testcase_21 | AC | 259 ms
60,812 KB |
testcase_22 | AC | 128 ms
52,664 KB |
testcase_23 | AC | 205 ms
58,568 KB |
testcase_24 | AC | 302 ms
62,104 KB |
testcase_25 | AC | 283 ms
60,972 KB |
testcase_26 | AC | 305 ms
61,408 KB |
testcase_27 | AC | 92 ms
51,520 KB |
testcase_28 | AC | 276 ms
60,596 KB |
testcase_29 | AC | 315 ms
64,056 KB |
testcase_30 | AC | 237 ms
58,728 KB |
testcase_31 | AC | 288 ms
61,084 KB |
testcase_32 | AC | 293 ms
60,896 KB |
testcase_33 | AC | 261 ms
60,540 KB |
testcase_34 | AC | 308 ms
63,344 KB |
testcase_35 | AC | 292 ms
60,924 KB |
testcase_36 | AC | 274 ms
61,036 KB |
testcase_37 | AC | 305 ms
63,488 KB |
testcase_38 | AC | 257 ms
60,648 KB |
testcase_39 | AC | 250 ms
60,460 KB |
testcase_40 | AC | 210 ms
58,412 KB |
testcase_41 | AC | 281 ms
60,652 KB |
testcase_42 | AC | 277 ms
60,832 KB |
testcase_43 | AC | 251 ms
60,800 KB |
testcase_44 | AC | 296 ms
61,096 KB |
testcase_45 | AC | 269 ms
60,844 KB |
testcase_46 | AC | 214 ms
58,640 KB |
testcase_47 | AC | 260 ms
60,932 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int h = sc.nextInt(); int w = sc.nextInt(); char[][] field = new char[h][]; UnionFindTree uft = new UnionFindTree(h * w); for (int i = 0; i < h; i++) { field[i] = sc.next().toCharArray(); for (int j = 0; j < w; j++) { if (i > 0) { if (field[i - 1][j] == field[i][j]) { uft.unite((i - 1) * w + j, i * w + j); } } if (j > 0) { if (field[i][j - 1] == field[i][j]) { uft.unite(i * w + j - 1, i * w + j); } } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (uft.getCount(i * w + j) >= 4) { field[i][j] = '.'; } } sb.append(new String(field[i])).append("\n"); } System.out.print(sb); } static class UnionFindTree { int[] parents; int[] counts; public UnionFindTree(int size) { parents = IntStream.range(0, size).toArray(); counts = new int[size]; Arrays.fill(counts, 1); } public int find(int x) { return x == parents[x] ? x : (parents[x] = find(parents[x])); } public boolean same(int x, int y) { return find(x) == find(y); } public void unite(int x, int y) { int xx = find(x); int yy = find(y); if (xx != yy) { parents[xx] = yy; counts[yy] += counts[xx]; } } public int getCount(int x) { return counts[find(x)]; } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }