結果
問題 | No.366 ロボットソート |
ユーザー |
![]() |
提出日時 | 2016-08-26 18:35:35 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 223 ms / 2,000 ms |
コード長 | 754 bytes |
コンパイル時間 | 4,400 ms |
コンパイル使用メモリ | 77,872 KB |
実行使用メモリ | 42,776 KB |
最終ジャッジ日時 | 2024-12-29 18:31:26 |
合計ジャッジ時間 | 8,513 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
import java.util.Arrays; import java.util.Scanner; public class Yuki366 { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int N, K; N = sc.nextInt(); K = sc.nextInt(); int[] A = new int[N]; int[] sortA = new int[N]; for (int i = 0; i < N; i++) { A[i] = sc.nextInt(); sortA[i] = A[i]; } Arrays.sort(sortA); int ans = Ksort(A, K); if (!Arrays.equals(A, sortA)) { ans = -1; } System.out.println(ans); } public static int Ksort(int[] A, int K) { int cnt = 0; for (int i = 0; i < A.length; i++) { for (int j = 0; j + K < A.length; j++) { if (A[j] > A[j + K]) { int buf = A[j]; A[j] = A[j + K]; A[j + K] = buf; cnt++; } } } return cnt; } }