結果
| 問題 |
No.366 ロボットソート
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-11-18 09:33:29 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 209 ms / 2,000 ms |
| コード長 | 953 bytes |
| コンパイル時間 | 2,170 ms |
| コンパイル使用メモリ | 74,856 KB |
| 実行使用メモリ | 54,596 KB |
| 最終ジャッジ日時 | 2024-07-23 08:52:23 |
| 合計ジャッジ時間 | 6,990 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int count = 0;
for (int i = 0; i < k; i++) {
for (int j = n; i + k < j; j -= k) {
for (int a = i; a + k < j; a += k) {
if (arr[a] > arr[a + k]) {
int tmp = arr[a];
arr[a] = arr[a + k];
arr[a + k] = tmp;
count++;
}
}
}
}
for (int i = 0; i < n - 1; i++) {
if (arr[i] > arr[i + 1]) {
System.out.println(-1);
return;
}
}
System.out.println(count);
}
}
tenten