結果

問題 No.1013 〇マス進む
ユーザー betrue12betrue12
提出日時 2020-03-20 21:49:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 2,167 ms
コンパイル使用メモリ 202,480 KB
実行使用メモリ 40,832 KB
最終ジャッジ日時 2024-05-08 21:41:47
合計ジャッジ時間 11,808 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 96 ms
21,504 KB
testcase_15 AC 174 ms
32,512 KB
testcase_16 AC 156 ms
29,952 KB
testcase_17 AC 87 ms
19,200 KB
testcase_18 AC 112 ms
22,656 KB
testcase_19 AC 65 ms
14,880 KB
testcase_20 AC 210 ms
39,040 KB
testcase_21 AC 78 ms
17,792 KB
testcase_22 AC 118 ms
23,296 KB
testcase_23 AC 35 ms
9,984 KB
testcase_24 AC 217 ms
40,448 KB
testcase_25 AC 209 ms
39,424 KB
testcase_26 AC 36 ms
9,984 KB
testcase_27 AC 74 ms
17,024 KB
testcase_28 AC 35 ms
10,236 KB
testcase_29 AC 200 ms
38,272 KB
testcase_30 AC 69 ms
15,576 KB
testcase_31 AC 129 ms
26,624 KB
testcase_32 AC 94 ms
20,736 KB
testcase_33 AC 100 ms
20,736 KB
testcase_34 AC 173 ms
30,848 KB
testcase_35 AC 183 ms
29,440 KB
testcase_36 AC 12 ms
5,504 KB
testcase_37 AC 12 ms
5,376 KB
testcase_38 AC 193 ms
33,664 KB
testcase_39 AC 59 ms
13,236 KB
testcase_40 AC 201 ms
30,720 KB
testcase_41 AC 40 ms
10,232 KB
testcase_42 AC 99 ms
19,840 KB
testcase_43 AC 61 ms
14,080 KB
testcase_44 AC 102 ms
20,992 KB
testcase_45 AC 89 ms
18,688 KB
testcase_46 AC 45 ms
11,008 KB
testcase_47 AC 93 ms
19,840 KB
testcase_48 AC 121 ms
22,784 KB
testcase_49 AC 200 ms
30,592 KB
testcase_50 AC 142 ms
26,624 KB
testcase_51 AC 126 ms
24,064 KB
testcase_52 AC 26 ms
7,808 KB
testcase_53 AC 36 ms
9,472 KB
testcase_54 AC 144 ms
29,184 KB
testcase_55 AC 48 ms
11,128 KB
testcase_56 AC 216 ms
36,224 KB
testcase_57 AC 161 ms
25,600 KB
testcase_58 AC 279 ms
40,704 KB
testcase_59 AC 260 ms
40,832 KB
testcase_60 AC 229 ms
40,832 KB
testcase_61 AC 204 ms
40,704 KB
testcase_62 AC 196 ms
40,704 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> P(2*N), pos(N+1);
    for(int i=0; i<N; i++){
        cin >> P[i];
        pos[P[i]] = i;
        P[i+N] = P[i];
    }
    static int dub[32][100000];
    static int64_t gain[32][100000];
    for(int i=0; i<N; i++){
        dub[0][i] = pos[P[i+P[i]]];
        gain[0][i] = P[i];
    }
    for(int k=0; k<30; k++) for(int i=0; i<N; i++){
        dub[k+1][i] = dub[k][dub[k][i]];
        gain[k+1][i] = gain[k][i] + gain[k][dub[k][i]];
    }
    for(int i=0; i<N; i++){
        int p = i;
        int64_t ans = i+1;
        for(int k=0; k<30; k++) if(nth_bit(K, k)){
            ans += gain[k][p];
            p = dub[k][p];
        }
        cout << ans << endl;
    }
    return 0;
}
0