結果
| 問題 |
No.1028 闇討ち
|
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2020-04-17 21:42:05 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 823 bytes |
| コンパイル時間 | 187 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 100,036 KB |
| 最終ジャッジ日時 | 2024-10-03 11:50:44 |
| 合計ジャッジ時間 | 22,255 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 TLE * 8 |
ソースコード
# 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