結果
| 問題 | No.421 しろくろチョコレート |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-02 16:47:47 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,455 bytes |
| 記録 | |
| コンパイル時間 | 222 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-11-21 13:04:27 |
| 合計ジャッジ時間 | 36,174 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 48 TLE * 2 |
ソースコード
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def solve(n, m, chocolate):
ans = 0
while True:
min_num = 5
min_pos = (None, None)
for y in range(n):
for x in range(m):
now = chocolate[y][x]
num = 0
for i in range(len(dy)):
ny, nx = y + dy[i], x + dx[i]
if 0 <= ny < n and 0 <= nx < m:
if now != "." and chocolate[ny][nx] != "." and chocolate[ny][nx] != now:
num += 1
if num != 0 and num < min_num:
min_num = num
min_pos = (y, x)
if min_num == 5:
break
y, x = min_pos
for i in range(len(dy)):
ny, nx = y + dy[i], x + dx[i]
if 0 <= ny < n and 0 <= nx < m:
if chocolate[ny][nx] != ".":
chocolate[y][x] = "."
chocolate[ny][nx] = "."
ans += 100
w, b = 0, 0
for y in range(n):
for x in range(m):
now = chocolate[y][x]
w += now == "w"
b += now == "b"
ans += min(w, b) * 10
ans += max(w, b) - min(w, b)
return ans
def main():
n, m = map(int, input().split())
chocolate = []
for _ in range(n):
chocolate.append(list(input()))
print(solve(n, m, chocolate))
if __name__ == '__main__':
main()