結果

問題 No.366 ロボットソート
ユーザー AoiroFukurouAoiroFukurou
提出日時 2016-05-07 15:32:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 3,716 ms
コンパイル使用メモリ 76,264 KB
実行使用メモリ 57,664 KB
最終ジャッジ日時 2023-08-28 15:15:13
合計ジャッジ時間 7,586 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
55,412 KB
testcase_01 AC 115 ms
56,108 KB
testcase_02 AC 114 ms
55,840 KB
testcase_03 AC 114 ms
55,432 KB
testcase_04 AC 112 ms
55,888 KB
testcase_05 AC 114 ms
55,656 KB
testcase_06 AC 114 ms
55,656 KB
testcase_07 AC 114 ms
55,984 KB
testcase_08 AC 116 ms
56,088 KB
testcase_09 AC 114 ms
55,340 KB
testcase_10 AC 125 ms
55,804 KB
testcase_11 AC 162 ms
56,084 KB
testcase_12 AC 160 ms
56,132 KB
testcase_13 AC 136 ms
56,232 KB
testcase_14 AC 158 ms
55,636 KB
testcase_15 AC 132 ms
55,640 KB
testcase_16 AC 139 ms
56,164 KB
testcase_17 AC 162 ms
56,024 KB
testcase_18 AC 162 ms
55,804 KB
testcase_19 AC 163 ms
55,876 KB
testcase_20 AC 115 ms
55,716 KB
testcase_21 AC 163 ms
57,664 KB
testcase_22 AC 166 ms
54,420 KB
権限があれば一括ダウンロードができます

ソースコード

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