結果

問題 No.707 書道
ユーザー kerotonokerotono
提出日時 2018-06-29 22:50:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 10,800 KB
実行使用メモリ 7,992 KB
最終ジャッジ日時 2023-09-13 15:30:27
合計ジャッジ時間 1,225 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,952 KB
testcase_01 AC 15 ms
7,840 KB
testcase_02 AC 33 ms
7,800 KB
testcase_03 AC 15 ms
7,752 KB
testcase_04 AC 15 ms
7,992 KB
testcase_05 AC 61 ms
7,888 KB
testcase_06 AC 86 ms
7,872 KB
testcase_07 AC 112 ms
7,852 KB
testcase_08 AC 17 ms
7,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!python
# -*- coding: utf-8 -*-


H, W = map(int, input().split())
grid = []


def get_time(x, y):
    t = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j]:
                t += ((x - (j + 1)) ** 2 + (y - (i + 1)) ** 2) ** (1 / 2)
    return t


def main():
    for i in range(H):
        grid.append(list(map(int, input())))

    ANS = float('inf')

    for y in range(1, H + 1):
        ANS = min(ANS, get_time(0, y))
        ANS = min(ANS, get_time(W + 1, y))

    for x in range(1, W + 1):
        ANS = min(ANS, get_time(x, 0))
        ANS = min(ANS, get_time(x, H + 1))

    print(ANS)


if __name__ == '__main__':
    main()
0