結果

問題 No.366 ロボットソート
ユーザー yun_appyun_app
提出日時 2016-05-10 14:07:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 1,176 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 73,680 KB
実行使用メモリ 52,200 KB
最終ジャッジ日時 2023-08-28 15:16:25
合計ジャッジ時間 4,232 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,120 KB
testcase_01 AC 42 ms
49,204 KB
testcase_02 AC 43 ms
49,464 KB
testcase_03 AC 44 ms
49,072 KB
testcase_04 AC 44 ms
49,444 KB
testcase_05 AC 43 ms
49,064 KB
testcase_06 AC 42 ms
48,948 KB
testcase_07 AC 43 ms
49,228 KB
testcase_08 AC 44 ms
49,448 KB
testcase_09 AC 43 ms
49,192 KB
testcase_10 AC 45 ms
49,032 KB
testcase_11 AC 63 ms
50,092 KB
testcase_12 AC 66 ms
49,888 KB
testcase_13 AC 47 ms
49,120 KB
testcase_14 AC 48 ms
49,104 KB
testcase_15 AC 45 ms
49,528 KB
testcase_16 AC 49 ms
49,120 KB
testcase_17 AC 58 ms
51,456 KB
testcase_18 AC 68 ms
50,084 KB
testcase_19 AC 61 ms
52,200 KB
testcase_20 AC 43 ms
48,964 KB
testcase_21 AC 54 ms
49,180 KB
testcase_22 AC 240 ms
51,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int n = Integer.parseInt(lines[0]);
        int k = Integer.parseInt(lines[1]);
        lines = br.readLine().split(" ");
        
        int[] arr = new int[n];
        int idx = 0;
        for(String st:lines){
            arr[idx++] = Integer.parseInt(st);
        }

        int tmp,ans = 0;
        for(int i=0;i<n-k;i++){
            if(arr[i] > arr[i+k]){
                tmp = arr[i];
                arr[i] = arr[i+k];
                arr[i+k] = tmp;
                i=-1;
                ++ans;
            }
        }
        tmp = -1;
        for(int i:arr){
            if(tmp>i){
                ans = -1;
                break;
            }
            tmp = i;
        }
        System.out.println(ans);
    }
}
0