結果
問題 | No.307 最近色塗る問題多くない? |
ユーザー | Grenache |
提出日時 | 2015-11-27 23:46:20 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,409 ms / 4,000 ms |
コード長 | 3,432 bytes |
コンパイル時間 | 3,926 ms |
コンパイル使用メモリ | 79,672 KB |
実行使用メモリ | 56,144 KB |
最終ジャッジ日時 | 2024-05-01 16:39:58 |
合計ジャッジ時間 | 20,824 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 113 ms
41,788 KB |
testcase_01 | AC | 127 ms
41,108 KB |
testcase_02 | AC | 122 ms
41,404 KB |
testcase_03 | AC | 126 ms
41,076 KB |
testcase_04 | AC | 176 ms
41,960 KB |
testcase_05 | AC | 123 ms
41,244 KB |
testcase_06 | AC | 137 ms
41,648 KB |
testcase_07 | AC | 292 ms
50,696 KB |
testcase_08 | AC | 492 ms
54,136 KB |
testcase_09 | AC | 369 ms
52,228 KB |
testcase_10 | AC | 273 ms
45,656 KB |
testcase_11 | AC | 338 ms
47,880 KB |
testcase_12 | AC | 124 ms
41,172 KB |
testcase_13 | AC | 284 ms
49,140 KB |
testcase_14 | AC | 230 ms
43,884 KB |
testcase_15 | AC | 257 ms
44,648 KB |
testcase_16 | AC | 242 ms
43,556 KB |
testcase_17 | AC | 409 ms
53,132 KB |
testcase_18 | AC | 699 ms
53,420 KB |
testcase_19 | AC | 571 ms
54,808 KB |
testcase_20 | AC | 190 ms
43,052 KB |
testcase_21 | AC | 542 ms
53,944 KB |
testcase_22 | AC | 505 ms
53,984 KB |
testcase_23 | AC | 1,100 ms
56,144 KB |
testcase_24 | AC | 707 ms
51,888 KB |
testcase_25 | AC | 884 ms
51,728 KB |
testcase_26 | AC | 1,318 ms
55,540 KB |
testcase_27 | AC | 421 ms
47,624 KB |
testcase_28 | AC | 526 ms
52,192 KB |
testcase_29 | AC | 257 ms
47,232 KB |
testcase_30 | AC | 1,409 ms
55,952 KB |
testcase_31 | AC | 476 ms
49,028 KB |
testcase_32 | AC | 436 ms
49,192 KB |
testcase_33 | AC | 407 ms
52,636 KB |
testcase_34 | AC | 470 ms
48,892 KB |
testcase_35 | AC | 459 ms
48,700 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); } } }