結果
| 問題 |
No.707 書道
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-30 00:13:39 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 127 ms / 2,000 ms |
| コード長 | 1,186 bytes |
| コンパイル時間 | 245 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-07-01 00:33:56 |
| 合計ジャッジ時間 | 1,185 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 |
ソースコード
# import platform
# ver = platform.python_version_tuple()
# if int(ver[1]) < 5:
# from fractions import gcd
# else:
# from math import gcd
# from itertools import accumulate, combinations, permutations, product
# from bisect import bisect, bisect_left
# from collections import Counter, defaultdict, deque
# from heapq import heappush, heappop
# from decimal import *
# getcontext().prec = 500
# from functools import lru_cache
# @lru_cache(maxsize=1024)
from sys import stdin, stdout
input = lambda: stdin.readline().rstrip()
write = stdout.write
def main():
position = []
for i in range(1, H + 1):
position.append((0, i))
position.append((W + 1, i))
for i in range(1, W + 1):
position.append((i, 0))
position.append((i, H + 1))
dist = float('inf')
for x, y in position:
dist = min(dist, calc(x, y))
print(dist)
def calc(x1, y1):
ret = 0
for y2, s1 in enumerate(P, start=1):
for x2, s2 in enumerate(s1, start=1):
if s2 == '1':
ret += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
return ret
H, W = map(int, input().split())
P = stdin.read().splitlines()
main()