結果

問題 No.1013 〇マス進む
ユーザー MisterMister
提出日時 2020-05-02 02:12:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 1,104 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 80,612 KB
実行使用メモリ 40,844 KB
最終ジャッジ日時 2023-08-26 20:49:26
合計ジャッジ時間 12,174 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 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,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 84 ms
20,968 KB
testcase_15 AC 142 ms
32,232 KB
testcase_16 AC 125 ms
29,884 KB
testcase_17 AC 73 ms
18,780 KB
testcase_18 AC 93 ms
22,308 KB
testcase_19 AC 54 ms
14,556 KB
testcase_20 AC 173 ms
38,760 KB
testcase_21 AC 69 ms
17,696 KB
testcase_22 AC 95 ms
23,032 KB
testcase_23 AC 31 ms
9,712 KB
testcase_24 AC 173 ms
39,912 KB
testcase_25 AC 171 ms
39,208 KB
testcase_26 AC 31 ms
9,616 KB
testcase_27 AC 64 ms
16,708 KB
testcase_28 AC 31 ms
9,588 KB
testcase_29 AC 165 ms
37,956 KB
testcase_30 AC 57 ms
15,172 KB
testcase_31 AC 107 ms
26,216 KB
testcase_32 AC 78 ms
20,200 KB
testcase_33 AC 84 ms
20,348 KB
testcase_34 AC 137 ms
30,624 KB
testcase_35 AC 145 ms
29,084 KB
testcase_36 AC 11 ms
4,812 KB
testcase_37 AC 10 ms
4,900 KB
testcase_38 AC 153 ms
33,240 KB
testcase_39 AC 49 ms
12,840 KB
testcase_40 AC 158 ms
30,108 KB
testcase_41 AC 34 ms
9,896 KB
testcase_42 AC 83 ms
19,528 KB
testcase_43 AC 53 ms
13,604 KB
testcase_44 AC 86 ms
20,828 KB
testcase_45 AC 76 ms
18,324 KB
testcase_46 AC 37 ms
10,332 KB
testcase_47 AC 80 ms
19,520 KB
testcase_48 AC 98 ms
22,528 KB
testcase_49 AC 156 ms
30,212 KB
testcase_50 AC 122 ms
26,296 KB
testcase_51 AC 106 ms
23,828 KB
testcase_52 AC 22 ms
6,900 KB
testcase_53 AC 31 ms
9,128 KB
testcase_54 AC 127 ms
28,628 KB
testcase_55 AC 41 ms
10,700 KB
testcase_56 AC 174 ms
35,768 KB
testcase_57 AC 127 ms
25,300 KB
testcase_58 AC 212 ms
40,804 KB
testcase_59 AC 196 ms
40,744 KB
testcase_60 AC 204 ms
40,844 KB
testcase_61 AC 183 ms
40,696 KB
testcase_62 AC 178 ms
40,792 KB
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;

void solve() {
    int n, m;
    std::cin >> n >> m;

    std::vector<int> ps(n);
    for (auto& p : ps) std::cin >> p;

    auto to = vec(31, vec(n, 0));
    auto cost = vec(31, vec(n, 0LL));
    for (int i = 0; i < n; ++i) {
        to[0][i] = (i + ps[i]) % n;
        cost[0][i] = ps[i];
    }

    for (int k = 1; k <= 30; ++k) {
        for (int i = 0; i < n; ++i) {
            to[k][i] = to[k - 1][to[k - 1][i]];
            cost[k][i] = cost[k - 1][i] + cost[k - 1][to[k - 1][i]];
        }
    }

    for (int i = 0; i < n; ++i) {
        int rem = m;
        lint ans = 0;
        int v = i;
        for (int k = 30; k >= 0; --k) {
            if (rem < (1 << k)) continue;
            ans += cost[k][v];
            v = to[k][v];
            rem -= (1 << k);
        }

        std::cout << ans + i + 1 << std::endl;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0