結果
問題 |
No.366 ロボットソート
|
ユーザー |
![]() |
提出日時 | 2018-09-19 00:18:49 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 187 ms / 2,000 ms |
コード長 | 971 bytes |
コンパイル時間 | 1,921 ms |
コンパイル使用メモリ | 77,432 KB |
実行使用メモリ | 43,196 KB |
最終ジャッジ日時 | 2024-07-18 08:10:25 |
合計ジャッジ時間 | 6,677 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
import java.util.Arrays; import java.util.Scanner; public class Main { static int cnt = 0; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int K = scan.nextInt(); int []a = new int[N]; int []b = new int[N]; for(int i = 0; i < N; i++) { a[i] = scan.nextInt(); b[i] = a[i]; } scan.close(); Arrays.sort(b); for(int i = 0; i < K; i++) { kStepBubbleSort(a, N - i, K); } for(int i = 0; i < N; i++) { if(a[i] != b[i]) { System.out.println("-1"); System.exit(0); } } System.out.println(cnt); // for(int i : a) { // System.out.print(i + " "); // } // System.out.println(); } static void kStepBubbleSort(int[]A, int n, int K) { boolean flag = true; while(flag) { flag = false; for(int i = n - 1; i - K >= 0; i -= K) { if(A[i] < A[i - K]) { int t = A[i]; A[i] = A[i - K]; A[i - K] = t; flag = true; cnt ++; } } } } }