結果

問題 No.1028 闇討ち
ユーザー rkyiolklorkyiolklo
提出日時 2020-04-25 09:58:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 489 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 43,292 KB
最終ジャッジ日時 2024-04-24 10:46:59
合計ジャッジ時間 6,295 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
16,256 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 28 ms
10,752 KB
testcase_04 AC 29 ms
10,752 KB
testcase_05 AC 39 ms
11,008 KB
testcase_06 AC 52 ms
10,880 KB
testcase_07 AC 30 ms
10,752 KB
testcase_08 AC 37 ms
10,752 KB
testcase_09 AC 515 ms
14,080 KB
testcase_10 AC 748 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