結果

問題 No.1028 闇討ち
ユーザー hedwig100hedwig100
提出日時 2020-04-18 10:41:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 953 ms / 2,000 ms
コード長 940 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 135,380 KB
最終ジャッジ日時 2024-04-14 20:32:04
合計ジャッジ時間 10,182 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
56,508 KB
testcase_01 AC 49 ms
56,656 KB
testcase_02 AC 47 ms
63,396 KB
testcase_03 AC 45 ms
56,612 KB
testcase_04 AC 45 ms
57,236 KB
testcase_05 AC 56 ms
67,768 KB
testcase_06 AC 63 ms
70,456 KB
testcase_07 AC 55 ms
66,400 KB
testcase_08 AC 57 ms
67,564 KB
testcase_09 AC 103 ms
79,028 KB
testcase_10 AC 119 ms
78,180 KB
testcase_11 AC 272 ms
87,884 KB
testcase_12 AC 899 ms
128,468 KB
testcase_13 AC 791 ms
128,260 KB
testcase_14 AC 529 ms
101,796 KB
testcase_15 AC 199 ms
84,660 KB
testcase_16 AC 939 ms
134,272 KB
testcase_17 AC 859 ms
134,540 KB
testcase_18 AC 894 ms
134,932 KB
testcase_19 AC 910 ms
134,772 KB
testcase_20 AC 953 ms
135,380 KB
testcase_21 AC 949 ms
135,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 20
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  heapq import heappop,heapify,heappush
from bisect import bisect_left
from functools import reduce
from math import gcd

def tot(x,idx):
    ret = 0
    for i in idx:
        ret += max(i[1],abs(i[0] - x))
    return ret

def main():
    n = int(input())
    a = [list(map(int,input().split())) for _ in range(n)]

    idx = [[] for _ in range(n)]
    for i in range(n):
        for j in range(n):
            p = a[i][j] - 1
            idx[p].append((i,j))
    
    ans = 0
    for i in range(n):
        idxs = idx[i]
        l = 0
        r = n
        for _ in range(30):
            mid = (r + l)//2
            if tot(mid - 1,idxs) < tot(mid,idxs):
                r = mid
            else:
                l = mid
        tmp = tot(l,idxs)
        ans += tmp
    
    print(ans)

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