結果
| 問題 |
No.307 最近色塗る問題多くない?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-11-27 23:30:55 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,028 bytes |
| コンパイル時間 | 3,778 ms |
| コンパイル使用メモリ | 79,780 KB |
| 実行使用メモリ | 69,392 KB |
| 最終ジャッジ日時 | 2024-09-14 00:48:57 |
| 合計ジャッジ時間 | 11,797 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 TLE * 1 -- * 27 |
ソースコード
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 {
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();
for (int tcase = 0; tcase < q; tcase++) {
int r = sc.nextInt() - 1;
int c = sc.nextInt() - 1;
int x = sc.nextInt();
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;
while (!qr.isEmpty()) {
int cr = qr.remove();
int cc = qc.remove();
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);
}
}
}
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);
}
}
}