結果

問題 No.366 ロボットソート
ユーザー ki_ki33ki_ki33
提出日時 2016-04-29 23:26:16
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,048 bytes
コンパイル時間 2,192 ms
コンパイル使用メモリ 77,504 KB
実行使用メモリ 54,808 KB
最終ジャッジ日時 2024-04-15 05:58:17
合計ジャッジ時間 6,769 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
53,000 KB
testcase_01 AC 109 ms
53,080 KB
testcase_02 AC 124 ms
53,948 KB
testcase_03 AC 120 ms
54,316 KB
testcase_04 WA -
testcase_05 AC 111 ms
53,132 KB
testcase_06 AC 105 ms
53,176 KB
testcase_07 AC 107 ms
52,904 KB
testcase_08 AC 114 ms
54,220 KB
testcase_09 WA -
testcase_10 AC 130 ms
54,116 KB
testcase_11 AC 176 ms
54,336 KB
testcase_12 AC 183 ms
54,808 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 122 ms
54,296 KB
testcase_21 AC 188 ms
54,796 KB
testcase_22 AC 198 ms
54,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static final long C =  1000000007;
	static final int CY = 1000000000;
	StringBuilder sb;

	public void calc() {
		sb = new StringBuilder();
		BufferedInputStream bs = new BufferedInputStream(System.in);

		Scanner sc = new Scanner(bs);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int ad;
		if (n%k == 0) {
			ad = 0;
		}else {
			ad = 1;
		}

		int[][] a = new int[k][ad+n/k];
		for (int i=0; i < n; i++) {
			a[i%k][i/k] = sc.nextInt();
			//System.out.println(i%k+":"+i/k);
		}


		long ans = 0;
		for (int v = 0; v < k; v++) {
			for (int i=0; i < a[v].length; i++) {
				for (int t=0; t <i; t++) {
					if (a[v][i] == 0) break;
					if (a[v][i] < a[v][t]) ans++;
				}
			}
			Arrays.sort(a[v]);
		}
		for (int i=1; i < n; i++) {
			if (a[(i-1)%k][(i-1)/k] > a[i%k][i/k]){
				ans = -1;
				break;
			}
		}

		System.out.println(ans);
	}

	public static void main(String[] args) {
		Main main = new Main();
		main.calc();

	}
}
0