結果

問題 No.1028 闇討ち
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-18 17:48:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,523 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 203,000 KB
最終ジャッジ日時 2023-09-04 16:16:46
合計ジャッジ時間 16,361 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,252 KB
testcase_01 AC 75 ms
71,340 KB
testcase_02 AC 76 ms
71,232 KB
testcase_03 AC 76 ms
71,236 KB
testcase_04 AC 76 ms
71,332 KB
testcase_05 AC 86 ms
76,160 KB
testcase_06 AC 96 ms
76,620 KB
testcase_07 AC 82 ms
71,064 KB
testcase_08 AC 84 ms
75,784 KB
testcase_09 AC 121 ms
80,948 KB
testcase_10 AC 138 ms
80,120 KB
testcase_11 AC 336 ms
100,944 KB
testcase_12 AC 1,348 ms
188,128 KB
testcase_13 AC 1,339 ms
187,164 KB
testcase_14 AC 682 ms
132,556 KB
testcase_15 AC 248 ms
94,188 KB
testcase_16 AC 1,509 ms
202,692 KB
testcase_17 AC 1,515 ms
202,632 KB
testcase_18 AC 1,516 ms
202,876 KB
testcase_19 AC 1,464 ms
202,760 KB
testcase_20 AC 1,483 ms
203,000 KB
testcase_21 AC 1,523 ms
202,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main1(n,a):
  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 v in range(n):
    ary=iary[v]
    mat=[0]*n
    tmp=0
    for x,y in ary:
      # ロスのない場所
      x-y,x+y
      tmp+=y
      if x-y>0:
        cnt=1
        for z in range(x-y-1,-1,-1):
          mat[z]+=cnt
          cnt+=1
      if x+y+1<n:
        cnt=1
        for z in range(x+y+1,n):
          mat[z]+=cnt
          cnt+=1
    tmp+=min(mat)
    ans+=tmp
    #print(v,":",tmp,mat)
  return ans
if __name__=='__main__':
  n=int(input())
  a=[list(map(int,input().split())) for _ in range(n)]
  ret1=main1(n,a)
  print(ret1)
0