結果
| 問題 |
No.307 最近色塗る問題多くない?
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-05-12 19:24:14 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,302 bytes |
| コンパイル時間 | 2,624 ms |
| コンパイル使用メモリ | 78,388 KB |
| 実行使用メモリ | 59,688 KB |
| 最終ジャッジ日時 | 2024-09-13 20:27:04 |
| 合計ジャッジ時間 | 25,876 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 WA * 2 |
ソースコード
import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt();
int w = sc.nextInt();
boolean[][] field = new boolean[h][w];
int tCount = 0;
int fCount = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
field[i][j] = (sc.nextInt() == 1);
if (field[i][j]) {
tCount++;
} else {
fCount++;
}
}
}
ArrayDeque<Path> deq = new ArrayDeque<>();
int q = sc.nextInt();
boolean last = true;
for (int i = 0; i < q; i++) {
if (tCount > 0 && fCount > 0) {
deq.add(new Path(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt() == 1));
} else {
sc.nextInt();
sc.nextInt();
last = (sc.nextInt() == 1);
}
while (deq.size() > 0) {
Path p = deq.poll();
if (p.row < 0 || p.row >= h || p.col < 0 || p.col >= w) {
continue;
}
if (field[p.row][p.col] == p.type) {
continue;
}
field[p.row][p.col] = p.type;
if (p.type) {
tCount++;
fCount--;
} else {
tCount--;
fCount++;
}
deq.add(new Path(p.row - 1, p.col, p.type));
deq.add(new Path(p.row + 1, p.col, p.type));
deq.add(new Path(p.row, p.col - 1, p.type));
deq.add(new Path(p.row, p.col + 1, p.type));
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (j > 0) {
sb.append(" ");
}
if (tCount > 0 && fCount > 0) {
if (field[i][j]) {
sb.append("1");
} else {
sb.append("0");
}
} else {
if (last) {
sb.append("1");
} else {
sb.append("0");
}
}
}
sb.append("\n");
}
System.out.print(sb);
}
static class Path {
int row;
int col;
boolean type;
public Path(int row, int col, boolean type) {
this.row = row;
this.col = col;
this.type = type;
}
}
}
htensai