結果

問題 No.1013 〇マス進む
ユーザー tentententen
提出日時 2021-03-01 14:25:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 871 ms / 2,000 ms
コード長 1,420 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 78,036 KB
実行使用メモリ 86,836 KB
最終ジャッジ日時 2024-04-14 03:41:55
合計ジャッジ時間 40,286 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
54,400 KB
testcase_01 AC 142 ms
53,988 KB
testcase_02 AC 141 ms
54,204 KB
testcase_03 AC 191 ms
54,248 KB
testcase_04 AC 157 ms
54,504 KB
testcase_05 AC 196 ms
54,512 KB
testcase_06 AC 196 ms
54,340 KB
testcase_07 AC 199 ms
54,412 KB
testcase_08 AC 199 ms
54,636 KB
testcase_09 AC 198 ms
54,644 KB
testcase_10 AC 198 ms
54,340 KB
testcase_11 AC 174 ms
54,340 KB
testcase_12 AC 204 ms
54,620 KB
testcase_13 AC 246 ms
57,656 KB
testcase_14 AC 547 ms
68,220 KB
testcase_15 AC 676 ms
78,664 KB
testcase_16 AC 693 ms
80,620 KB
testcase_17 AC 543 ms
65,844 KB
testcase_18 AC 599 ms
69,236 KB
testcase_19 AC 478 ms
63,644 KB
testcase_20 AC 791 ms
81,660 KB
testcase_21 AC 522 ms
65,556 KB
testcase_22 AC 642 ms
69,060 KB
testcase_23 AC 347 ms
58,808 KB
testcase_24 AC 811 ms
82,436 KB
testcase_25 AC 844 ms
84,908 KB
testcase_26 AC 367 ms
59,000 KB
testcase_27 AC 523 ms
65,376 KB
testcase_28 AC 361 ms
62,840 KB
testcase_29 AC 745 ms
82,528 KB
testcase_30 AC 486 ms
65,688 KB
testcase_31 AC 671 ms
72,020 KB
testcase_32 AC 579 ms
65,704 KB
testcase_33 AC 594 ms
65,872 KB
testcase_34 AC 793 ms
78,208 KB
testcase_35 AC 734 ms
82,540 KB
testcase_36 AC 265 ms
57,868 KB
testcase_37 AC 264 ms
57,796 KB
testcase_38 AC 743 ms
80,756 KB
testcase_39 AC 439 ms
63,596 KB
testcase_40 AC 718 ms
77,028 KB
testcase_41 AC 375 ms
62,956 KB
testcase_42 AC 561 ms
68,128 KB
testcase_43 AC 447 ms
65,336 KB
testcase_44 AC 611 ms
69,396 KB
testcase_45 AC 566 ms
67,012 KB
testcase_46 AC 384 ms
61,008 KB
testcase_47 AC 581 ms
67,696 KB
testcase_48 AC 641 ms
70,044 KB
testcase_49 AC 731 ms
78,176 KB
testcase_50 AC 691 ms
78,292 KB
testcase_51 AC 660 ms
73,096 KB
testcase_52 AC 325 ms
60,652 KB
testcase_53 AC 357 ms
59,200 KB
testcase_54 AC 735 ms
76,408 KB
testcase_55 AC 402 ms
61,232 KB
testcase_56 AC 853 ms
83,536 KB
testcase_57 AC 724 ms
75,740 KB
testcase_58 AC 820 ms
86,836 KB
testcase_59 AC 847 ms
86,092 KB
testcase_60 AC 871 ms
85,600 KB
testcase_61 AC 817 ms
85,000 KB
testcase_62 AC 831 ms
85,200 KB
testcase_63 AC 149 ms
53,988 KB
testcase_64 AC 147 ms
54,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] permulation = new int[n];
        int[] base = new int[n];
        for (int i = 0; i < n; i++) {
            permulation[i] = sc.nextInt();
            base[i] = i;
        }
        int[][] idxes = new int[31][n];
        int[][] counts = new int[31][n];
        for (int i = 0; i < n; i++) {
            idxes[0][i] = (i + permulation[i]) % n;
            if (i + permulation[i] >= n) {
                counts[0][i] = 1;
            }
        }
        for (int i = 1; i < 31; i++) {
            for (int j = 0; j < n; j++) {
                idxes[i][j] = idxes[i - 1][idxes[i - 1][j]];
                counts[i][j] = counts[i - 1][j] + counts[i - 1][idxes[i - 1][j]];
            }
        }
        long[] add = new long[n];
        for (int i = 30; i >= 0; i--) {
            if (k >= (1 << i)) {
                k -= (1 << i);
                for (int j = 0; j < n; j++) {
                    add[j] += counts[i][base[j]];
                    base[j] = idxes[i][base[j]];
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(add[i] * n + base[i] + 1).append("\n");
        }
        System.out.print(sb);
    }
}
0