結果

問題 No.1028 闇討ち
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-18 17:19:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 586 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 203,256 KB
最終ジャッジ日時 2023-09-04 15:11:52
合計ジャッジ時間 10,937 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,132 KB
testcase_01 AC 78 ms
71,136 KB
testcase_02 AC 76 ms
71,264 KB
testcase_03 AC 77 ms
70,924 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
iary=[[] for _ in range(n)]
ans=0
for i in range(n):
  for j in range(n):
    iary[a[i][j]-1].append([i,j])
for i in range(n):
  ary=iary[i]
  mat=[0]*n
  for x,y in ary:
    # ロスのない場所
    x-y,x+y
    if x-y>0:
      mat[0]+=1
      mat[x-y]-=1
    if x+y+1<n:
      mat[x+y+1]+=1
  min_idx=0
  min_v=mat[0]
  for i in range(n-1):
    mat[i+1]+=mat[i]
    if mat[i+1]<min_v:
      min_v=mat[i+1]
      min_idx=i+1
  tmp=0
  for x,y in ary:
    x=abs(x-min_idx)
    tmp+=y+max(0,x-y)
  ans+=tmp
print(ans)
0