結果

問題 No.707 書道
ユーザー maspymaspy
提出日時 2020-01-29 23:23:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,828 KB
実行使用メモリ 29,928 KB
最終ジャッジ日時 2023-10-14 07:58:27
合計ジャッジ時間 2,301 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
29,824 KB
testcase_01 AC 147 ms
29,772 KB
testcase_02 AC 150 ms
29,832 KB
testcase_03 AC 148 ms
29,736 KB
testcase_04 AC 144 ms
29,728 KB
testcase_05 AC 148 ms
29,904 KB
testcase_06 AC 149 ms
29,916 KB
testcase_07 AC 151 ms
29,928 KB
testcase_08 AC 150 ms
29,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W = map(int,readline().split())
P = np.frombuffer(read(),'S1').reshape(H,-1)[:,:W]

P = (P == b'1') * 1

def gen_position():
    for x in range(H):
        yield (x,-1)
        yield (x,W)
    for y in range(W):
        yield (-1,y)
        yield (H,y)

opt_value = 10 ** 18
for x,y in gen_position():
    dx = np.arange(H) - x
    dy = np.arange(W) - y
    D = np.sqrt((dx*dx)[:,None] + (dy*dy)[None,:])
    value = (D * P).sum()
    if opt_value > value:
        opt_value = value

print(opt_value)
0