結果

問題 No.1013 〇マス進む
ユーザー NOSSNOSS
提出日時 2020-03-20 22:14:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 1,147 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 173,136 KB
実行使用メモリ 53,632 KB
最終ジャッジ日時 2024-05-08 22:21:42
合計ジャッジ時間 11,931 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 9 ms
5,376 KB
testcase_14 AC 101 ms
27,520 KB
testcase_15 AC 174 ms
42,368 KB
testcase_16 AC 155 ms
39,040 KB
testcase_17 AC 89 ms
24,192 KB
testcase_18 AC 115 ms
29,056 KB
testcase_19 AC 65 ms
18,688 KB
testcase_20 AC 212 ms
51,072 KB
testcase_21 AC 82 ms
22,528 KB
testcase_22 AC 117 ms
29,952 KB
testcase_23 AC 37 ms
11,904 KB
testcase_24 AC 218 ms
52,736 KB
testcase_25 AC 207 ms
51,584 KB
testcase_26 AC 38 ms
11,904 KB
testcase_27 AC 76 ms
21,504 KB
testcase_28 AC 36 ms
12,032 KB
testcase_29 AC 203 ms
50,048 KB
testcase_30 AC 67 ms
19,584 KB
testcase_31 AC 133 ms
34,304 KB
testcase_32 AC 94 ms
26,368 KB
testcase_33 AC 103 ms
26,368 KB
testcase_34 AC 177 ms
40,064 KB
testcase_35 AC 183 ms
38,016 KB
testcase_36 AC 12 ms
5,760 KB
testcase_37 AC 12 ms
5,632 KB
testcase_38 AC 196 ms
43,904 KB
testcase_39 AC 62 ms
16,384 KB
testcase_40 AC 192 ms
39,808 KB
testcase_41 AC 42 ms
12,160 KB
testcase_42 AC 103 ms
25,344 KB
testcase_43 AC 63 ms
17,408 KB
testcase_44 AC 108 ms
26,752 KB
testcase_45 AC 94 ms
23,680 KB
testcase_46 AC 46 ms
13,056 KB
testcase_47 AC 101 ms
25,216 KB
testcase_48 AC 119 ms
29,312 KB
testcase_49 AC 246 ms
39,680 KB
testcase_50 AC 182 ms
34,304 KB
testcase_51 AC 151 ms
31,104 KB
testcase_52 AC 29 ms
8,704 KB
testcase_53 AC 36 ms
11,264 KB
testcase_54 AC 149 ms
37,760 KB
testcase_55 AC 49 ms
13,440 KB
testcase_56 AC 208 ms
47,104 KB
testcase_57 AC 154 ms
33,024 KB
testcase_58 AC 266 ms
53,632 KB
testcase_59 AC 251 ms
53,632 KB
testcase_60 AC 232 ms
53,632 KB
testcase_61 AC 208 ms
53,632 KB
testcase_62 AC 204 ms
53,632 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;

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<double,P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-9;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for(int i=0;i<N;i++){
        cin >> p[i];
    }
    vector<vector<P> > dp(31, vector<P>(N));  // dp[k][i] マスiから2**k回移動したときの(マスのindex,移動数)
    for(int i=0;i<N;i++){
        dp[0][i] = P((i+p[i])%N, p[i]);
    }
    for(int k=0;k<30;k++){
        for(int i=0;i<N;i++){
            ll idx = dp[k][i].first, cnt = dp[k][i].second;
            dp[k+1][i] = P(dp[k][idx].first, dp[k][idx].second+cnt);
        }
    }
    for(int i=0;i<N;i++){
        ll ans = i+1;
        int now = i;
        for(int k=0;k<=30;k++){
            if((K>>k)&1){
                ans += dp[k][now].second;
                now = dp[k][now].first;
            }
        }
        cout << ans << endl;
    }
    return 0;
}
0