結果
| 問題 | No.366 ロボットソート | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2016-09-02 23:11:09 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 235 ms / 2,000 ms | 
| コード長 | 757 bytes | 
| コンパイル時間 | 3,242 ms | 
| コンパイル使用メモリ | 77,428 KB | 
| 実行使用メモリ | 42,816 KB | 
| 最終ジャッジ日時 | 2024-12-29 18:31:39 | 
| 合計ジャッジ時間 | 7,818 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
import java.util.Arrays;
import java.util.Scanner;
public class Main {	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] a = new int[N];
		int[] sub = new int[N];
		
		for(int i=0; i<N; i++){
			a[i] = sc.nextInt();
			sub[i] = a[i];
		}
		Arrays.sort(sub);
		int cnt = Robo_sort(a,N ,K);
		
		if(!Arrays.equals(a, sub)){
			System.out.println("-1");
		}else{		
			System.out.println(cnt);
		}
	}
	public static int Robo_sort(int[] a, int N , int K){
		int count = 0;
		for(int i=0; i<N-K; i++){
			for(int j=0; j<N-K; j++){
				if(a[j] > a[j+K]){
					int temp = a[j];
					a[j] = a[j+K];
					a[j+K] = temp;
					count ++;
				}
			}
		}
		return count;
	}
}
		
		
            
            
            
        