結果

問題 No.1028 闇討ち
ユーザー AEnAEn
提出日時 2022-12-03 15:31:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 1,044 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 94,080 KB
最終ジャッジ日時 2024-04-19 01:11:12
合計ジャッジ時間 5,104 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,224 KB
testcase_01 AC 43 ms
51,968 KB
testcase_02 AC 42 ms
52,096 KB
testcase_03 AC 42 ms
51,712 KB
testcase_04 AC 41 ms
51,840 KB
testcase_05 AC 46 ms
52,992 KB
testcase_06 AC 61 ms
63,744 KB
testcase_07 AC 39 ms
52,608 KB
testcase_08 AC 42 ms
52,992 KB
testcase_09 AC 82 ms
74,752 KB
testcase_10 AC 94 ms
77,568 KB
testcase_11 AC 124 ms
78,464 KB
testcase_12 AC 235 ms
92,032 KB
testcase_13 AC 259 ms
89,088 KB
testcase_14 AC 180 ms
85,120 KB
testcase_15 AC 114 ms
79,360 KB
testcase_16 AC 281 ms
94,080 KB
testcase_17 AC 264 ms
93,824 KB
testcase_18 AC 246 ms
93,696 KB
testcase_19 AC 252 ms
93,696 KB
testcase_20 AC 265 ms
93,952 KB
testcase_21 AC 255 ms
93,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

acc = [[0]*(N+1) for _ in range(N)]
cost = [0]*N
for i in range(N):
    for j in range(N):
        id = A[i][j]-1
        cost[id] += max(i,j)
        if i==0:
            if j+1<=N:
                acc[id][j+1] += 1
                acc[id][-1] -= 1
        elif j==0:
            acc[id][1] -= 1
            acc[id][i+1] += 1
            acc[id][i+1] += 1
            acc[id][-1] -= 1
        elif i==j:
            if i*2+1<=N:
                acc[id][i*2+1] += 1
                acc[id][-1] -= 1
        elif i>j:
            acc[id][1] -= 1
            acc[id][i-j+1] += 1
            if i+j+1<=N:
                acc[id][i+j+1] += 1
                acc[id][-1] -= 1
        else:
            if i+j+1<=N:
                acc[id][i+j+1] += 1
                acc[id][-1] -= 1
res = 0
for i in range(N):
    for j in range(N):
        acc[i][j+1] += acc[i][j]
    for j in range(N):
        acc[i][j+1] += acc[i][j]
    res += cost[i]+min(acc[i][:-1])
print(res)
    
0