結果

問題 No.1028 闇討ち
ユーザー rkyiolklorkyiolklo
提出日時 2020-04-25 09:58:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 969 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 81,708 KB
実行使用メモリ 134,400 KB
最終ジャッジ日時 2024-04-24 10:48:07
合計ジャッジ時間 10,119 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,224 KB
testcase_01 AC 38 ms
52,480 KB
testcase_02 AC 38 ms
57,600 KB
testcase_03 AC 34 ms
52,352 KB
testcase_04 AC 38 ms
52,480 KB
testcase_05 AC 54 ms
67,328 KB
testcase_06 AC 66 ms
73,984 KB
testcase_07 AC 52 ms
65,152 KB
testcase_08 AC 55 ms
67,072 KB
testcase_09 AC 119 ms
78,612 KB
testcase_10 AC 138 ms
79,780 KB
testcase_11 AC 269 ms
87,668 KB
testcase_12 AC 794 ms
129,024 KB
testcase_13 AC 914 ms
128,540 KB
testcase_14 AC 474 ms
103,428 KB
testcase_15 AC 231 ms
84,992 KB
testcase_16 AC 969 ms
133,500 KB
testcase_17 AC 855 ms
132,952 KB
testcase_18 AC 851 ms
134,016 KB
testcase_19 AC 926 ms
133,828 KB
testcase_20 AC 928 ms
134,400 KB
testcase_21 AC 824 ms
133,632 KB
権限があれば一括ダウンロードができます

ソースコード

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