結果

問題 No.1013 〇マス進む
ユーザー NOSSNOSS
提出日時 2020-03-20 22:14:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 1,147 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 171,288 KB
実行使用メモリ 53,712 KB
最終ジャッジ日時 2023-08-21 16:55:45
合計ジャッジ時間 12,017 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 9 ms
4,896 KB
testcase_14 AC 104 ms
27,028 KB
testcase_15 AC 181 ms
42,372 KB
testcase_16 AC 162 ms
38,636 KB
testcase_17 AC 87 ms
24,188 KB
testcase_18 AC 116 ms
28,868 KB
testcase_19 AC 68 ms
18,316 KB
testcase_20 AC 222 ms
50,916 KB
testcase_21 AC 83 ms
22,336 KB
testcase_22 AC 122 ms
29,668 KB
testcase_23 AC 36 ms
11,840 KB
testcase_24 AC 223 ms
52,644 KB
testcase_25 AC 220 ms
51,412 KB
testcase_26 AC 38 ms
11,728 KB
testcase_27 AC 77 ms
21,348 KB
testcase_28 AC 37 ms
11,840 KB
testcase_29 AC 212 ms
49,728 KB
testcase_30 AC 73 ms
19,648 KB
testcase_31 AC 136 ms
34,216 KB
testcase_32 AC 98 ms
26,052 KB
testcase_33 AC 104 ms
25,992 KB
testcase_34 AC 184 ms
39,960 KB
testcase_35 AC 180 ms
37,868 KB
testcase_36 AC 12 ms
5,652 KB
testcase_37 AC 11 ms
5,536 KB
testcase_38 AC 202 ms
43,692 KB
testcase_39 AC 62 ms
16,044 KB
testcase_40 AC 205 ms
39,824 KB
testcase_41 AC 40 ms
12,016 KB
testcase_42 AC 106 ms
25,276 KB
testcase_43 AC 66 ms
17,252 KB
testcase_44 AC 108 ms
26,236 KB
testcase_45 AC 95 ms
23,620 KB
testcase_46 AC 48 ms
12,904 KB
testcase_47 AC 98 ms
24,972 KB
testcase_48 AC 122 ms
29,136 KB
testcase_49 AC 208 ms
39,560 KB
testcase_50 AC 148 ms
34,100 KB
testcase_51 AC 132 ms
30,712 KB
testcase_52 AC 25 ms
8,568 KB
testcase_53 AC 35 ms
10,956 KB
testcase_54 AC 149 ms
37,540 KB
testcase_55 AC 49 ms
13,336 KB
testcase_56 AC 219 ms
46,776 KB
testcase_57 AC 164 ms
32,828 KB
testcase_58 AC 297 ms
53,552 KB
testcase_59 AC 268 ms
53,452 KB
testcase_60 AC 235 ms
53,424 KB
testcase_61 AC 212 ms
53,712 KB
testcase_62 AC 204 ms
53,536 KB
testcase_63 AC 2 ms
4,376 KB
testcase_64 AC 2 ms
4,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