結果

問題 No.366 ロボットソート
ユーザー Mcpu3Mcpu3
提出日時 2018-09-04 23:02:39
言語 Java
(openjdk 23)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 504 bytes
コンパイル時間 2,315 ms
コンパイル使用メモリ 75,328 KB
実行使用メモリ 54,904 KB
最終ジャッジ日時 2024-11-06 11:58:37
合計ジャッジ時間 7,370 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),k=sc.nextInt(),a[]=new int[n],s=0,t,i,j;
		for(i=0;i<n;++i) a[i]=sc.nextInt();
		sc.close();
		for(i=0;i<n-k;++i) {
			for(j=n-1;j>=i+k;--j) {
				if(a[j-k]>a[j]) {
					t=a[j-k];
					a[j-k]=a[j];
					a[j]=t;
					++s;
				}
			}
		}
		for(i=1;i<n;++i) if(a[i-1]>a[i]) break;
		if(i==n) System.out.print(s);
		else System.out.print(-1);
	}
}
0