結果

問題 No.1028 闇討ち
ユーザー convexineqconvexineq
提出日時 2020-04-17 21:42:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 823 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 179,316 KB
最終ジャッジ日時 2024-04-14 13:23:06
合計ジャッジ時間 4,989 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,308 KB
testcase_01 AC 39 ms
52,520 KB
testcase_02 AC 37 ms
53,008 KB
testcase_03 AC 38 ms
53,484 KB
testcase_04 AC 37 ms
53,164 KB
testcase_05 AC 44 ms
60,024 KB
testcase_06 AC 55 ms
65,236 KB
testcase_07 AC 38 ms
52,744 KB
testcase_08 AC 40 ms
53,552 KB
testcase_09 AC 69 ms
77,020 KB
testcase_10 AC 80 ms
82,160 KB
testcase_11 AC 119 ms
103,000 KB
testcase_12 AC 306 ms
171,980 KB
testcase_13 AC 301 ms
172,108 KB
testcase_14 AC 185 ms
133,040 KB
testcase_15 AC 102 ms
96,404 KB
testcase_16 AC 325 ms
178,556 KB
testcase_17 AC 324 ms
178,432 KB
testcase_18 AC 324 ms
178,636 KB
testcase_19 AC 326 ms
178,388 KB
testcase_20 AC 330 ms
178,700 KB
testcase_21 AC 321 ms
179,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!
def kaisa2_of_tousa(a,b,p,q,imos):
    if p > q: return
    imos[p] += b
    if p+1 < n: imos[p+1] += a-b
    y = a*(q-p)+b
    if q+1 < n: imos[q+1] += -y-a
    if q+2 < n: imos[q+2] += y


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

n,*a = [int(i) for i in read().split()]

res = [[0]*n for _ in range(n)]
for i in range(n):
    ai = a[n*i:n*(i+1)]
    for j,aij in enumerate(ai):
        kaisa2_of_tousa(0,j,0,n-1,res[aij-1])
        if i-j > 0:
            kaisa2_of_tousa(-1,i-j,0,i-j,res[aij-1])
        if i+j < n-1:
            kaisa2_of_tousa(1,0,i+j,n-1,res[aij-1])

from itertools import accumulate as acc
ans = [0]*n
for i in range(n):
    #print(list(acc(acc(res[i]))))
    ans[i] = min(acc(acc(res[i])))

print(sum(ans))





0