結果

問題 No.1028 闇討ち
ユーザー convexineqconvexineq
提出日時 2020-04-17 21:42:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 823 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 99,992 KB
最終ジャッジ日時 2024-04-14 13:22:59
合計ジャッジ時間 23,274 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 30 ms
10,752 KB
testcase_03 AC 30 ms
10,624 KB
testcase_04 AC 33 ms
10,752 KB
testcase_05 AC 33 ms
11,008 KB
testcase_06 AC 33 ms
10,880 KB
testcase_07 AC 30 ms
11,008 KB
testcase_08 AC 31 ms
11,008 KB
testcase_09 AC 98 ms
13,308 KB
testcase_10 AC 128 ms
14,592 KB
testcase_11 AC 548 ms
28,736 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 AC 1,243 ms
54,468 KB
testcase_15 AC 390 ms
23,716 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
権限があれば一括ダウンロードができます

ソースコード

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