結果
| 問題 |
No.421 しろくろチョコレート
|
| ユーザー |
htensai
|
| 提出日時 | 2019-11-20 02:16:31 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,666 bytes |
| コンパイル時間 | 1,991 ms |
| コンパイル使用メモリ | 80,392 KB |
| 実行使用メモリ | 56,336 KB |
| 最終ジャッジ日時 | 2024-10-04 20:12:44 |
| 合計ジャッジ時間 | 12,436 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 WA * 33 |
ソースコード
import java.util.*;
public class Main {
public static void main (String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int h = sc.nextInt();
int w = sc.nextInt();
char[][] field = new char[h + 2][];
int bCount = 0;
int wCount = 0;
for (int i = 0; i <= h + 1; i++) {
if (i == 0 || i == h + 1) {
field[i] = new char[w + 2];
Arrays.fill(field[i], '.');
continue;
}
field[i] = ("." + sc.next() + ".").toCharArray();
for (int j = 1; j <= w; j++) {
if (field[i][j] == 'w') {
wCount++;
} else if (field[i][j] == 'b') {
bCount++;
}
}
}
int[][] counts = new int[h + 2][w + 2];
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (field[i][j] != '.') {
if (field[i - 1][j] != '.') {
counts[i][j]++;
}
if (field[i + 1][j] != '.') {
counts[i][j]++;
}
if (field[i][j - 1] != '.') {
counts[i][j]++;
}
if (field[i][j + 1] != '.') {
counts[i][j]++;
}
}
}
}
boolean flag = true;
int point = 0;
while (flag) {
flag = false;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (counts[i][j] == 1) {
if (counts[i - 1][j] > 0) {
counts[i - 1][j] = 0;
counts[i][j] = 0;
counts[i - 2][j]--;
counts[i - 1][j - 1]--;
counts[i - 1][j + 1]--;
wCount--;
bCount--;
flag = true;
point += 100;
break;
}
if (counts[i + 1][j] > 0) {
counts[i][j] = 0;
counts[i + 1][j] = 0;
counts[i + 2][j]--;
counts[i + 1][j - 1]--;
counts[i + 1][j + 1]--;
wCount--;
bCount--;
flag = true;
point += 100;
break;
}
if (counts[i][j - 1] > 0) {
counts[i][j] = 0;
counts[i][j - 1] = 0;
counts[i][j - 2]--;
counts[i - 1][j - 1]--;
counts[i + 1][j - 1]--;
wCount--;
bCount--;
flag = true;
point += 100;
break;
}
if (counts[i][j + 1] > 0) {
counts[i][j] = 0;
counts[i][j + 1] = 0;
counts[i][j + 2]--;
counts[i - 1][j + 1]--;
counts[i + 1][j + 1]--;
wCount--;
bCount--;
flag = true;
point += 100;
break;
}
}
}
}
}
int allCount = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (counts[i][j] > 0) {
allCount++;
}
}
}
point += allCount / 2 * 100;
bCount -= allCount / 2;
wCount -= allCount / 2;
int max = Math.max(wCount, bCount);
int min = Math.min(wCount, bCount);
point += 10 * min;
point += max - min;
System.out.println(point);
}
}
htensai