結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
17,952 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 31 ms
11,008 KB
testcase_04 AC 30 ms
11,136 KB
testcase_05 AC 51 ms
11,008 KB
testcase_06 AC 74 ms
11,136 KB
testcase_07 AC 36 ms
11,008 KB
testcase_08 AC 48 ms
11,008 KB
testcase_09 AC 840 ms
14,336 KB
testcase_10 AC 1,213 ms
15,872 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 #

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