結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
41,468 KB
testcase_01 AC 118 ms
41,368 KB
testcase_02 AC 113 ms
41,112 KB
testcase_03 AC 115 ms
41,404 KB
testcase_04 WA -
testcase_05 AC 116 ms
40,872 KB
testcase_06 AC 120 ms
41,340 KB
testcase_07 AC 115 ms
41,420 KB
testcase_08 AC 117 ms
41,388 KB
testcase_09 WA -
testcase_10 AC 129 ms
41,716 KB
testcase_11 AC 174 ms
42,964 KB
testcase_12 AC 175 ms
42,972 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 108 ms
40,512 KB
testcase_21 AC 197 ms
42,692 KB
testcase_22 AC 199 ms
43,064 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[][] a = new int[k][1+n/k];
		for (int i=0; i < n; i++) {
			a[i%k][i/k] = sc.nextInt();
		}


		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