結果
問題 | No.366 ロボットソート |
ユーザー | kenji_shioya |
提出日時 | 2016-05-27 17:56:31 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,229 bytes |
コンパイル時間 | 3,528 ms |
コンパイル使用メモリ | 77,772 KB |
実行使用メモリ | 52,996 KB |
最終ジャッジ日時 | 2024-04-16 17:45:41 |
合計ジャッジ時間 | 8,120 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 135 ms
41,344 KB |
testcase_01 | AC | 130 ms
41,128 KB |
testcase_02 | AC | 132 ms
41,192 KB |
testcase_03 | WA | - |
testcase_04 | AC | 132 ms
41,492 KB |
testcase_05 | AC | 132 ms
41,500 KB |
testcase_06 | AC | 133 ms
41,528 KB |
testcase_07 | AC | 136 ms
41,488 KB |
testcase_08 | AC | 132 ms
41,372 KB |
testcase_09 | AC | 128 ms
41,564 KB |
testcase_10 | AC | 145 ms
41,764 KB |
testcase_11 | AC | 190 ms
42,584 KB |
testcase_12 | AC | 192 ms
42,616 KB |
testcase_13 | AC | 176 ms
41,784 KB |
testcase_14 | AC | 180 ms
41,968 KB |
testcase_15 | AC | 167 ms
41,688 KB |
testcase_16 | AC | 178 ms
41,776 KB |
testcase_17 | AC | 181 ms
41,856 KB |
testcase_18 | AC | 201 ms
42,716 KB |
testcase_19 | AC | 186 ms
41,780 KB |
testcase_20 | AC | 131 ms
41,728 KB |
testcase_21 | AC | 207 ms
42,852 KB |
testcase_22 | AC | 209 ms
43,056 KB |
ソースコード
import java.util.*; public class Exercises22{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); int size = sc.nextInt(); int armWidth = sc.nextInt(); int[] array = new int[size]; for (int n = 0; n < size; n++){ array[n] = sc.nextInt(); } int count = 0; boolean flag = false; for (int a = 0; a < armWidth; a++){ for (int k = a; k < getLastIndex(a, size, armWidth); k += armWidth){ for(int i = getLastIndex(a, size, armWidth); k < i; i -= armWidth){ if (array[i] < array[i - armWidth]){ int w = array[i]; array[i] = array[i - armWidth]; array[i - armWidth] = w; count++; } } } } for (int n = 1; n < size; n++){ if (array[n - 1] <= array[n]){ flag = true; }else{ flag = false; break; } } if(flag == true){ System.out.println(count); }else{ System.out.println(-1); } } private static int getLastIndex(int a, int size, int armWidth){ int extr = 0; if (size % armWidth > a){ extr = 1; } return (size / armWidth - 1 + extr) * armWidth + a; } }