結果
問題 |
No.366 ロボットソート
|
ユーザー |
![]() |
提出日時 | 2021-03-22 02:46:36 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 142 ms / 2,000 ms |
コード長 | 707 bytes |
コンパイル時間 | 102 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-11-22 21:38:13 |
合計ジャッジ時間 | 1,954 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#!/usr/bin/env python3 #coding:utf-8 import math from sys import stdin # import numpy as np # from matplotlib import pyplot as plt def main(): read=stdin.readline #edit here! n,k=map(int,read().split()) a=list(map(int,read().split())) ans=0 for i in range(0,k): v=[] for j in range(i,n,k): v.append(a[j]) flag=True cnt=0 j=0 while flag: flag=False sz=len(v) for x in range(sz-1,j,-1): if v[x-1]>v[x]: v[x-1],v[x]=v[x],v[x-1] flag=True cnt+=1 j+=1 ans+=cnt for j in range(i,n,k): a[j]=v[j//k] ng=False for i in range(n-1): if a[i]>a[i+1]: ng=True if ng!=True: print(ans) else : print(-1) if __name__ == '__main__': main()