結果

問題 No.366 ロボットソート
ユーザー Mcpu3Mcpu3
提出日時 2018-09-04 23:02:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 207 ms / 2,000 ms
コード長 504 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 74,416 KB
実行使用メモリ 43,060 KB
最終ジャッジ日時 2024-04-24 05:03:14
合計ジャッジ時間 6,648 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
41,540 KB
testcase_01 AC 107 ms
41,524 KB
testcase_02 AC 117 ms
41,652 KB
testcase_03 AC 118 ms
41,312 KB
testcase_04 AC 126 ms
41,476 KB
testcase_05 AC 125 ms
41,776 KB
testcase_06 AC 116 ms
40,300 KB
testcase_07 AC 108 ms
41,352 KB
testcase_08 AC 118 ms
41,660 KB
testcase_09 AC 117 ms
41,060 KB
testcase_10 AC 134 ms
42,436 KB
testcase_11 AC 185 ms
43,060 KB
testcase_12 AC 190 ms
42,740 KB
testcase_13 AC 155 ms
42,064 KB
testcase_14 AC 167 ms
42,336 KB
testcase_15 AC 164 ms
42,252 KB
testcase_16 AC 192 ms
42,172 KB
testcase_17 AC 196 ms
42,780 KB
testcase_18 AC 207 ms
42,532 KB
testcase_19 AC 174 ms
42,248 KB
testcase_20 AC 122 ms
41,508 KB
testcase_21 AC 186 ms
42,896 KB
testcase_22 AC 184 ms
42,704 KB
権限があれば一括ダウンロードができます

ソースコード

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