結果
問題 | No.366 ロボットソート |
ユーザー |
![]() |
提出日時 | 2016-07-28 15:43:46 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 757 bytes |
コンパイル時間 | 1,531 ms |
コンパイル使用メモリ | 159,424 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 18:29:40 |
合計ジャッジ時間 | 2,569 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define INF 1000000000 #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++) int N,K; int a[1001]; int main(){ cin>>N>>K; REP(i,N){ cin>>a[i]; } long long count=0; REP(i,K){ for(int k=0;;k++){ for(int j=0;;j++){ if(j*K+i+K>=N)break; int t=j*K+i; int t2=t+K; if(a[t]>a[t2]){ int temp=a[t]; a[t]=a[t2]; a[t2]=temp; count++; } } if(k*K+i+K>=N)break; } } REP(i,N-1){ if(a[i]>a[i+1]){ cout<<-1<<endl; return 0; } } cout<<count<<endl; }