結果

問題 No.1028 闇討ち
ユーザー freecss00freecss00
提出日時 2020-04-17 22:23:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 495 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 43,680 KB
最終ジャッジ日時 2024-04-14 14:39:46
合計ジャッジ時間 5,982 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
17,696 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 30 ms
10,880 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 44 ms
10,752 KB
testcase_06 AC 59 ms
10,880 KB
testcase_07 AC 33 ms
10,752 KB
testcase_08 AC 41 ms
10,752 KB
testcase_09 AC 566 ms
14,208 KB
testcase_10 AC 811 ms
15,744 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = [list(map(lambda a:int(a)-1, input().split())) for _ in range(n)]
h = [[] for _ in range(n)]
for i in range(n):
    for j in range(n):
        h[a[i][j]].append((i,j))

ans = 0
for i in range(n):
    fn = lambda p: sum([max(abs(p - pi), pj) for pi, pj in h[i]])
    l, r = 0, n-1
    for _ in range(20):
        a = (l*2 + r) // 3
        b = (l + r*2) // 3
        if fn(a) > fn(b):
            l = a
        else:
            r = b
    ans += min(fn(a), fn(b))
print(ans)
0