結果
| 問題 |
No.1028 闇討ち
|
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2020-04-17 21:42:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 368 ms / 2,000 ms |
| コード長 | 823 bytes |
| コンパイル時間 | 723 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 178,940 KB |
| 最終ジャッジ日時 | 2024-10-03 11:51:03 |
| 合計ジャッジ時間 | 5,284 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
# 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))
convexineq