結果

問題 No.1013 〇マス進む
ユーザー tentententen
提出日時 2023-06-08 13:05:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 462 ms / 2,000 ms
コード長 2,532 bytes
コンパイル時間 4,030 ms
コンパイル使用メモリ 81,216 KB
実行使用メモリ 94,960 KB
最終ジャッジ日時 2023-08-29 02:47:45
合計ジャッジ時間 25,665 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
34,996 KB
testcase_01 AC 53 ms
34,784 KB
testcase_02 AC 54 ms
35,036 KB
testcase_03 AC 64 ms
35,308 KB
testcase_04 AC 56 ms
35,220 KB
testcase_05 AC 65 ms
35,400 KB
testcase_06 AC 64 ms
35,384 KB
testcase_07 AC 68 ms
35,620 KB
testcase_08 AC 64 ms
35,364 KB
testcase_09 AC 67 ms
35,512 KB
testcase_10 AC 67 ms
35,436 KB
testcase_11 AC 61 ms
35,256 KB
testcase_12 AC 69 ms
35,776 KB
testcase_13 AC 97 ms
37,852 KB
testcase_14 AC 290 ms
64,356 KB
testcase_15 AC 369 ms
79,368 KB
testcase_16 AC 345 ms
75,556 KB
testcase_17 AC 265 ms
62,504 KB
testcase_18 AC 314 ms
65,684 KB
testcase_19 AC 245 ms
54,784 KB
testcase_20 AC 403 ms
90,964 KB
testcase_21 AC 263 ms
60,612 KB
testcase_22 AC 316 ms
66,324 KB
testcase_23 AC 183 ms
48,404 KB
testcase_24 AC 440 ms
94,464 KB
testcase_25 AC 415 ms
91,828 KB
testcase_26 AC 180 ms
48,316 KB
testcase_27 AC 254 ms
61,916 KB
testcase_28 AC 183 ms
48,152 KB
testcase_29 AC 385 ms
89,896 KB
testcase_30 AC 246 ms
56,072 KB
testcase_31 AC 314 ms
70,312 KB
testcase_32 AC 290 ms
62,912 KB
testcase_33 AC 325 ms
66,104 KB
testcase_34 AC 350 ms
79,912 KB
testcase_35 AC 382 ms
78,596 KB
testcase_36 AC 140 ms
40,092 KB
testcase_37 AC 138 ms
40,200 KB
testcase_38 AC 399 ms
84,148 KB
testcase_39 AC 240 ms
52,952 KB
testcase_40 AC 391 ms
85,932 KB
testcase_41 AC 189 ms
48,492 KB
testcase_42 AC 301 ms
62,556 KB
testcase_43 AC 244 ms
54,084 KB
testcase_44 AC 314 ms
65,860 KB
testcase_45 AC 295 ms
61,340 KB
testcase_46 AC 203 ms
49,908 KB
testcase_47 AC 282 ms
62,800 KB
testcase_48 AC 318 ms
65,468 KB
testcase_49 AC 401 ms
85,992 KB
testcase_50 AC 344 ms
71,804 KB
testcase_51 AC 308 ms
67,760 KB
testcase_52 AC 158 ms
44,604 KB
testcase_53 AC 185 ms
47,680 KB
testcase_54 AC 373 ms
77,412 KB
testcase_55 AC 206 ms
49,720 KB
testcase_56 AC 437 ms
87,860 KB
testcase_57 AC 349 ms
69,632 KB
testcase_58 AC 462 ms
92,112 KB
testcase_59 AC 462 ms
92,384 KB
testcase_60 AC 455 ms
93,436 KB
testcase_61 AC 426 ms
94,960 KB
testcase_62 AC 422 ms
94,720 KB
testcase_63 AC 54 ms
34,900 KB
testcase_64 AC 53 ms
34,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[][] values = new long[30][n];
        int[][] nexts = new int[30][n];
        int[] idxes = new int[n];
        long[] ans = new long[n];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            nexts[0][i] = (i + x) % n;
            values[0][i] = x;
            idxes[i] = i;
            ans[i] = i + 1;
        }
        for (int i = 1; i < 30; i++) {
            for (int j = 0; j < n; j++) {
                nexts[i][j] = nexts[i - 1][nexts[i - 1][j]];
                values[i][j] = values[i - 1][j] + values[i - 1][nexts[i - 1][j]];
            }
        }
        for (int i = 29; i >= 0; i--) {
            if (k < (1 << i)) {
                continue;
            }
            k -= (1 << i);
            int[] pidxes = new int[n];
            for (int j = 0; j < n; j++) {
                ans[j] += values[i][idxes[j]];
                idxes[j] = nexts[i][idxes[j]];
            }
        }
        System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new)));
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0