結果
| 問題 |
No.307 最近色塗る問題多くない?
|
| コンテスト | |
| ユーザー |
atkrym
|
| 提出日時 | 2016-10-18 17:48:35 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,573 bytes |
| コンパイル時間 | 2,370 ms |
| コンパイル使用メモリ | 77,304 KB |
| 実行使用メモリ | 126,384 KB |
| 最終ジャッジ日時 | 2024-11-22 12:26:42 |
| 合計ジャッジ時間 | 44,553 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 TLE * 4 |
ソースコード
import java.util.*;
public class Main {
private static Scanner sc = new Scanner(System.in);
private static int[][] ary;
private static int h;
private static int w;
public static void main(String[] args) throws Exception {
h = sc.nextInt();
w = sc.nextInt();
ary = new int[h][w];
for (int i = 0;i < h;i++) {
for (int j = 0;j < w;j++) {
ary[i][j] = sc.nextInt();
}
}
int q = sc.nextInt();
for (int i = 0;i < q;i++) {
int x = sc.nextInt() - 1;
int y = sc.nextInt() - 1;
int c = sc.nextInt();
int pc = ary[x][y];
draw(x, y, c, pc);
}
show();
}
private static void draw(int x, int y, int c, int pc) {
ary[x][y] = c;
int[] dx = {-1, 0, 1, 0};
int[] dy = {0, 1, 0, -1};
for (int i = 0;i < 4;i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (0 <= nx && nx < h && 0 <= ny && ny < w) {
int nc = ary[nx][ny];
if (pc == nc && c != nc) {
draw(nx, ny, c, pc);
}
}
}
}
private static void show() {
for (int i = 0;i < h;i++) {
StringBuilder sb = new StringBuilder();
for (int j = 0;j < w;j++) {
sb.append(ary[i][j]).append(" ");
}
System.out.println(sb.substring(0, sb.length()-1));
}
}
}
atkrym