結果

問題 No.1013 〇マス進む
ユーザー betrue12betrue12
提出日時 2020-03-20 21:49:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 2,831 ms
コンパイル使用メモリ 199,012 KB
実行使用メモリ 41,392 KB
最終ジャッジ日時 2023-08-21 16:10:07
合計ジャッジ時間 12,591 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,016 KB
testcase_01 AC 2 ms
5,024 KB
testcase_02 AC 2 ms
4,952 KB
testcase_03 AC 3 ms
5,236 KB
testcase_04 AC 3 ms
5,144 KB
testcase_05 AC 2 ms
4,952 KB
testcase_06 AC 3 ms
5,016 KB
testcase_07 AC 3 ms
4,956 KB
testcase_08 AC 3 ms
5,020 KB
testcase_09 AC 10 ms
38,168 KB
testcase_10 AC 10 ms
38,196 KB
testcase_11 AC 9 ms
38,268 KB
testcase_12 AC 10 ms
38,152 KB
testcase_13 AC 15 ms
38,304 KB
testcase_14 AC 89 ms
39,688 KB
testcase_15 AC 151 ms
40,636 KB
testcase_16 AC 140 ms
40,440 KB
testcase_17 AC 79 ms
39,420 KB
testcase_18 AC 99 ms
39,768 KB
testcase_19 AC 61 ms
38,952 KB
testcase_20 AC 178 ms
41,168 KB
testcase_21 AC 72 ms
39,152 KB
testcase_22 AC 103 ms
39,836 KB
testcase_23 AC 36 ms
38,820 KB
testcase_24 AC 187 ms
41,160 KB
testcase_25 AC 184 ms
41,264 KB
testcase_26 AC 37 ms
38,716 KB
testcase_27 AC 69 ms
39,128 KB
testcase_28 AC 37 ms
38,640 KB
testcase_29 AC 173 ms
40,928 KB
testcase_30 AC 64 ms
39,092 KB
testcase_31 AC 118 ms
40,124 KB
testcase_32 AC 86 ms
39,792 KB
testcase_33 AC 91 ms
39,688 KB
testcase_34 AC 154 ms
40,404 KB
testcase_35 AC 155 ms
40,388 KB
testcase_36 AC 17 ms
38,292 KB
testcase_37 AC 16 ms
38,336 KB
testcase_38 AC 165 ms
40,872 KB
testcase_39 AC 58 ms
38,872 KB
testcase_40 AC 167 ms
40,428 KB
testcase_41 AC 41 ms
38,660 KB
testcase_42 AC 92 ms
39,472 KB
testcase_43 AC 60 ms
38,940 KB
testcase_44 AC 95 ms
39,640 KB
testcase_45 AC 83 ms
39,348 KB
testcase_46 AC 45 ms
38,676 KB
testcase_47 AC 90 ms
39,372 KB
testcase_48 AC 106 ms
39,640 KB
testcase_49 AC 166 ms
40,424 KB
testcase_50 AC 129 ms
40,172 KB
testcase_51 AC 113 ms
39,860 KB
testcase_52 AC 28 ms
38,756 KB
testcase_53 AC 36 ms
38,812 KB
testcase_54 AC 132 ms
40,404 KB
testcase_55 AC 48 ms
38,728 KB
testcase_56 AC 186 ms
40,940 KB
testcase_57 AC 138 ms
39,972 KB
testcase_58 AC 238 ms
41,392 KB
testcase_59 AC 221 ms
41,168 KB
testcase_60 AC 199 ms
41,212 KB
testcase_61 AC 182 ms
41,212 KB
testcase_62 AC 176 ms
41,160 KB
testcase_63 AC 8 ms
38,360 KB
testcase_64 AC 9 ms
38,120 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