結果

問題 No.707 書道
ユーザー 💕💖💞💕💖💞
提出日時 2018-08-03 00:44:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 777 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 42,348 KB
最終ジャッジ日時 2023-10-19 21:13:53
合計ジャッジ時間 6,281 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 486 ms
42,348 KB
testcase_01 AC 488 ms
42,348 KB
testcase_02 AC 536 ms
42,348 KB
testcase_03 AC 485 ms
42,348 KB
testcase_04 AC 483 ms
42,348 KB
testcase_05 AC 620 ms
42,348 KB
testcase_06 AC 695 ms
42,348 KB
testcase_07 AC 777 ms
42,348 KB
testcase_08 AC 484 ms
42,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
import math
(height, width) = map(int, input().split())
b = np.zeros((height+2, width+2))
for h in range(height):
  for w, ch in enumerate(input()):
    if ch == '1':
      b[h+1,w+1] = 1.0
key_l2 = {}
for ww in [0, width+1]:
  for h in range(1, height+1):
    w = ww
    key = (h,w)
    for h2 in range(1, height+1):
      for w2 in range(1, width+1):
        if b[h2, w2] != 1.0: 
          continue
        if key_l2.get(key) is None:
          key_l2[key] = 0.0
        key_l2[key] += math.sqrt( (h - h2)**2 + (w - w2)**2 )
for hh in [0, height+1]:
  for w in range(1, width+1):
    h = hh
    key = (h,w)
    for h2 in range(1, height+1):
      for w2 in range(1, width+1):
        if b[h2, w2] != 1.0: 
          continue
        if key_l2.get(key) is None:
          key_l2[key] = 0.0
        key_l2[key] += math.sqrt( (h - h2)**2 + (w - w2)**2 )
if len(key_l2) > 0:
  print(min([f for key, f in key_l2.items()]))
else:
  print(0)
0