結果

問題 No.1028 闇討ち
ユーザー freecss00freecss00
提出日時 2020-04-17 22:23:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,072 ms / 2,000 ms
コード長 495 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 134,232 KB
最終ジャッジ日時 2024-04-14 14:40:10
合計ジャッジ時間 11,229 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,476 KB
testcase_01 AC 37 ms
53,440 KB
testcase_02 AC 41 ms
58,124 KB
testcase_03 AC 38 ms
53,028 KB
testcase_04 AC 37 ms
53,312 KB
testcase_05 AC 58 ms
68,512 KB
testcase_06 AC 69 ms
74,308 KB
testcase_07 AC 53 ms
65,436 KB
testcase_08 AC 57 ms
67,824 KB
testcase_09 AC 133 ms
78,664 KB
testcase_10 AC 154 ms
79,928 KB
testcase_11 AC 301 ms
87,648 KB
testcase_12 AC 886 ms
129,244 KB
testcase_13 AC 1,007 ms
129,216 KB
testcase_14 AC 541 ms
103,132 KB
testcase_15 AC 247 ms
85,072 KB
testcase_16 AC 1,072 ms
133,424 KB
testcase_17 AC 955 ms
133,492 KB
testcase_18 AC 953 ms
133,804 KB
testcase_19 AC 1,038 ms
133,768 KB
testcase_20 AC 1,037 ms
134,232 KB
testcase_21 AC 919 ms
133,412 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