結果

問題 No.1028 闇討ち
ユーザー d9etd9et
提出日時 2020-04-17 22:07:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 542 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 101,984 KB
最終ジャッジ日時 2024-04-14 14:18:11
合計ジャッジ時間 4,470 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,808 KB
testcase_01 AC 37 ms
52,392 KB
testcase_02 AC 38 ms
54,012 KB
testcase_03 AC 39 ms
54,156 KB
testcase_04 AC 38 ms
52,936 KB
testcase_05 AC 42 ms
58,700 KB
testcase_06 AC 49 ms
62,852 KB
testcase_07 AC 38 ms
53,440 KB
testcase_08 AC 43 ms
58,952 KB
testcase_09 AC 69 ms
76,552 KB
testcase_10 AC 74 ms
77,112 KB
testcase_11 AC 105 ms
81,508 KB
testcase_12 AC 227 ms
98,516 KB
testcase_13 AC 224 ms
98,492 KB
testcase_14 AC 150 ms
88,320 KB
testcase_15 AC 93 ms
80,376 KB
testcase_16 AC 244 ms
101,300 KB
testcase_17 AC 242 ms
101,984 KB
testcase_18 AC 240 ms
101,332 KB
testcase_19 AC 246 ms
101,356 KB
testcase_20 AC 245 ms
101,804 KB
testcase_21 AC 242 ms
101,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from itertools import accumulate
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
ls = [[0 for i in range(n)] for j in range(n)]
cost = 0
for i in range(n):
  for j in range(n):
    x = a[i][j]
    x -= 1
    cost += max(i,j)
    if i>j:
      ls[x][1] += -1
      if i-j+1<n:
        ls[x][i-j+1] += 1
    if i+j<n-1:
      ls[x][i+j+1] += 1
for i in range(n):
  ls[i] = list(accumulate(ls[i]))
  ls[i] = list(accumulate(ls[i]))
for i in range(n):
  cost += min(ls[i])
print(cost)
0