結果

問題 No.1028 闇討ち
ユーザー mkawa2mkawa2
提出日時 2021-05-14 10:10:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,319 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 151,420 KB
最終ジャッジ日時 2024-04-09 02:13:41
合計ジャッジ時間 5,219 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
54,132 KB
testcase_01 AC 35 ms
53,200 KB
testcase_02 AC 34 ms
52,536 KB
testcase_03 AC 34 ms
53,304 KB
testcase_04 AC 34 ms
52,952 KB
testcase_05 AC 40 ms
60,012 KB
testcase_06 AC 52 ms
64,596 KB
testcase_07 AC 39 ms
54,584 KB
testcase_08 AC 43 ms
59,724 KB
testcase_09 AC 70 ms
77,192 KB
testcase_10 AC 74 ms
77,672 KB
testcase_11 AC 111 ms
85,920 KB
testcase_12 AC 264 ms
134,960 KB
testcase_13 AC 265 ms
134,120 KB
testcase_14 AC 165 ms
99,064 KB
testcase_15 AC 98 ms
82,468 KB
testcase_16 AC 278 ms
150,160 KB
testcase_17 AC 274 ms
150,568 KB
testcase_18 AC 277 ms
150,780 KB
testcase_19 AC 285 ms
151,420 KB
testcase_20 AC 283 ms
150,956 KB
testcase_21 AC 275 ms
150,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
dij = [(0, 1), (1, 0), (1, 1), (1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

n=II()
aa=LLI1(n)
ii=[[] for _ in range(n)]
jj=[[] for _ in range(n)]
for i,row in enumerate(aa):
    for j,a in enumerate(row):
        ii[a].append(i)
        jj[a].append(j)

ans=0
for a in range(n):
    cs=[[0]*(n+3) for _ in range(3)]
    for i,j in zip(ii[a],jj[a]):
        ans+=j
        l,r=i-j,i+j+1
        if l>0:
            cs[0][0]+=l
            cs[0][1]-=l+1
            cs[0][l+1]+=1
        if r<n:
            cs[0][r]+=1
    for i in range(2):
        for j in range(n):
            cs[i+1][j]=cs[i+1][j-1]+cs[i][j]
    ans+=min(cs[2][:n])

print(ans)
0