結果

問題 No.366 ロボットソート
ユーザー AoiroFukurou
提出日時 2016-05-07 15:32:02
言語 Java
(openjdk 23)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 4,945 ms
コンパイル使用メモリ 77,148 KB
実行使用メモリ 41,436 KB
最終ジャッジ日時 2024-12-29 17:51:44
合計ジャッジ時間 9,960 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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++){//int型に変換
		n[i] = Integer.parseInt(sn[i]);
	}
	long[] val = new long[n[0]];
	for(int i = 0; i < n[0]; i++){//int型に変換
		val[i] = Integer.parseInt(sn2[i]);
	}
	int Output = 0;//出力
	int MVal = n[0] - n[1] - 1;
	flag: for(int i = 0; i <= n[0]; i++){
				for(int j = 0; j <= MVal; j++){
					if(0 > MVal){
						break flag;
		}
		if(val[j] > val[j + n[1]]){//ソート
			long memory = val[j];
			val[j] = val[j + n[1]];
			val[j + 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