結果

問題 No.366 ロボットソート
ユーザー AoiroFukurou
提出日時 2016-05-07 15:02:01
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,045 bytes
コンパイル時間 3,185 ms
コンパイル使用メモリ 77,504 KB
実行使用メモリ 54,776 KB
最終ジャッジ日時 2024-10-05 10:18:15
合計ジャッジ時間 6,902 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

package yuki_coder;

import java.util.Scanner;

public class No_366 {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String S1 = sc.nextLine();
	String S2 = sc.nextLine();
	String[] sn = S1.split(" ", -1);
	String[] sn2 = S2.split(" ", -1);
	int[] n = new int[2];
	for(int i = 0; i < 2; i++){
		n[i] = Integer.parseInt(sn[i]);
	}
	int[] val = new int[n[0]];
	for(int i = 0; i < n[0]; i++){
		val[i] = Integer.parseInt(sn2[i]);
	}
	int Output = 0;
	int MVal = n[0] - n[1] - 1;
	for(int i = 0; i <= MVal; i++){
		if(i==0 && i >= MVal){
			break;
		}
		if(val[i] > val[i + n[1]]){//ソート
			int memory = val[i];
			val[i] = val[i + n[1]];
			val[i + n[1]] = memory;
			Output++;
		}
	}
	if(Output != 0 && n[0] >= n[1]){//一番最初を再比較
		if(val[0] > val[n[1]]){
		int memory = val[0];
		val[0] = val[n[1]];
		val[n[1]] = memory;
		Output++;
	}
	}
	for(int i = 1; i < n[0]; i++){//数字のソートの確認
		if(val[i - 1] > val[i]){
			Output = -1;
			break;
		}
	}
	System.out.println(Output);
}
}
0