結果

問題 No.366 ロボットソート
ユーザー ki_ki33ki_ki33
提出日時 2016-04-29 23:30:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 2,826 ms
コンパイル使用メモリ 74,408 KB
実行使用メモリ 57,336 KB
最終ジャッジ日時 2023-08-28 15:12:14
合計ジャッジ時間 6,381 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,352 KB
testcase_01 AC 120 ms
56,360 KB
testcase_02 AC 119 ms
55,952 KB
testcase_03 AC 120 ms
55,556 KB
testcase_04 AC 121 ms
55,920 KB
testcase_05 AC 120 ms
56,236 KB
testcase_06 AC 121 ms
56,508 KB
testcase_07 AC 120 ms
55,712 KB
testcase_08 AC 120 ms
56,260 KB
testcase_09 AC 121 ms
56,220 KB
testcase_10 AC 136 ms
56,236 KB
testcase_11 AC 180 ms
56,276 KB
testcase_12 AC 185 ms
56,256 KB
testcase_13 AC 174 ms
55,824 KB
testcase_14 AC 175 ms
55,980 KB
testcase_15 AC 151 ms
55,820 KB
testcase_16 AC 169 ms
56,088 KB
testcase_17 AC 176 ms
56,044 KB
testcase_18 AC 190 ms
55,956 KB
testcase_19 AC 179 ms
56,152 KB
testcase_20 AC 124 ms
56,356 KB
testcase_21 AC 196 ms
57,336 KB
testcase_22 AC 196 ms
56,252 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 < k; i++) {
			Arrays.fill(a[i], Integer.MAX_VALUE);
		}
		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] == Integer.MAX_VALUE) 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