結果

問題 No.366 ロボットソート
ユーザー AoiroFukurouAoiroFukurou
提出日時 2016-05-07 15:02:01
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,045 bytes
コンパイル時間 4,105 ms
コンパイル使用メモリ 77,344 KB
実行使用メモリ 41,844 KB
最終ジャッジ日時 2024-04-15 13:36:27
合計ジャッジ時間 8,786 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
41,180 KB
testcase_01 AC 150 ms
41,304 KB
testcase_02 AC 157 ms
41,408 KB
testcase_03 AC 155 ms
41,728 KB
testcase_04 WA -
testcase_05 AC 147 ms
41,244 KB
testcase_06 AC 153 ms
41,136 KB
testcase_07 WA -
testcase_08 AC 144 ms
41,288 KB
testcase_09 WA -
testcase_10 AC 154 ms
41,504 KB
testcase_11 AC 187 ms
41,472 KB
testcase_12 AC 191 ms
41,376 KB
testcase_13 AC 166 ms
41,488 KB
testcase_14 AC 183 ms
41,400 KB
testcase_15 AC 172 ms
41,164 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 150 ms
41,828 KB
testcase_21 AC 180 ms
41,600 KB
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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