結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー | Grenache |
提出日時 | 2015-11-27 23:46:20 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,317 ms / 4,000 ms |
コード長 | 3,432 bytes |
コンパイル時間 | 6,420 ms |
コンパイル使用メモリ | 78,868 KB |
実行使用メモリ | 56,216 KB |
最終ジャッジ日時 | 2024-11-21 21:54:11 |
合計ジャッジ時間 | 20,590 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 116 ms
41,440 KB |
testcase_01 | AC | 115 ms
41,164 KB |
testcase_02 | AC | 117 ms
41,204 KB |
testcase_03 | AC | 115 ms
41,024 KB |
testcase_04 | AC | 172 ms
42,628 KB |
testcase_05 | AC | 123 ms
41,252 KB |
testcase_06 | AC | 129 ms
41,112 KB |
testcase_07 | AC | 282 ms
50,668 KB |
testcase_08 | AC | 480 ms
54,044 KB |
testcase_09 | AC | 361 ms
52,716 KB |
testcase_10 | AC | 267 ms
45,728 KB |
testcase_11 | AC | 343 ms
47,136 KB |
testcase_12 | AC | 120 ms
41,096 KB |
testcase_13 | AC | 292 ms
49,852 KB |
testcase_14 | AC | 232 ms
43,500 KB |
testcase_15 | AC | 252 ms
44,044 KB |
testcase_16 | AC | 231 ms
44,140 KB |
testcase_17 | AC | 393 ms
52,316 KB |
testcase_18 | AC | 650 ms
53,412 KB |
testcase_19 | AC | 603 ms
55,984 KB |
testcase_20 | AC | 186 ms
42,628 KB |
testcase_21 | AC | 532 ms
53,832 KB |
testcase_22 | AC | 494 ms
55,156 KB |
testcase_23 | AC | 1,116 ms
56,216 KB |
testcase_24 | AC | 632 ms
51,756 KB |
testcase_25 | AC | 850 ms
56,076 KB |
testcase_26 | AC | 1,317 ms
56,068 KB |
testcase_27 | AC | 418 ms
48,596 KB |
testcase_28 | AC | 499 ms
51,896 KB |
testcase_29 | AC | 261 ms
49,600 KB |
testcase_30 | AC | 1,296 ms
55,008 KB |
testcase_31 | AC | 461 ms
49,152 KB |
testcase_32 | AC | 444 ms
49,712 KB |
testcase_33 | AC | 388 ms
53,452 KB |
testcase_34 | AC | 444 ms
49,068 KB |
testcase_35 | AC | 450 ms
48,904 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.Arrays; import java.util.Iterator; import java.util.Queue; public class Main_yukicoder307_1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int[] dr = {-1, 1, 0, 0}; int[] dc = {0, 0, -1, 1}; int h = sc.nextInt(); int w = sc.nextInt(); int[][] a = new int[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { a[i][j] = sc.nextInt(); } } int q = sc.nextInt(); boolean flag = false; int retc = 0; for (int tcase = 0; tcase < q; tcase++) { int r = sc.nextInt() - 1; int c = sc.nextInt() - 1; int x = sc.nextInt(); if (flag) { retc = x; continue; } if (x == a[r][c]) { continue; } int cp = a[r][c]; Queue<Integer> qr = new ArrayDeque<Integer>(); Queue<Integer> qc = new ArrayDeque<Integer>(); qr.add(r); qc.add(c); a[r][c] = x; int cnt = 0; while (!qr.isEmpty()) { int cr = qr.remove(); int cc = qc.remove(); cnt++; for (int i = 0; i < dr.length; i++) { int tmpr = cr + dr[i]; int tmpc = cc + dc[i]; if (tmpr < 0 || tmpr >= h || tmpc < 0 || tmpc >= w) { continue; } if (a[tmpr][tmpc] != cp) { continue; } a[tmpr][tmpc] = x; qr.add(tmpr); qc.add(tmpc); } } if (cnt == h * w) { flag = true; } } if (flag) { for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { a[i][j] = retc; } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j == 0) { pr.printf("%d", a[i][j]); } else { pr.printf(" %d", a[i][j]); } } pr.println(""); } pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }