結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
29,716 KB
testcase_01 AC 141 ms
29,868 KB
testcase_02 AC 144 ms
29,788 KB
testcase_03 AC 141 ms
29,724 KB
testcase_04 AC 142 ms
29,656 KB
testcase_05 AC 144 ms
29,848 KB
testcase_06 AC 148 ms
29,812 KB
testcase_07 AC 145 ms
29,912 KB
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

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(H):
        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