結果

問題 No.1013 〇マス進む
ユーザー hiroaki0615hiroaki0615
提出日時 2020-03-21 11:20:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 991 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 85,936 KB
実行使用メモリ 33,228 KB
最終ジャッジ日時 2023-08-23 08:19:54
合計ジャッジ時間 24,088 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 18 ms
4,460 KB
testcase_14 AC 289 ms
17,436 KB
testcase_15 AC 553 ms
26,444 KB
testcase_16 AC 471 ms
24,512 KB
testcase_17 AC 260 ms
15,724 KB
testcase_18 AC 351 ms
18,796 KB
testcase_19 AC 177 ms
12,352 KB
testcase_20 AC 652 ms
31,536 KB
testcase_21 AC 227 ms
14,464 KB
testcase_22 AC 345 ms
19,112 KB
testcase_23 AC 88 ms
8,424 KB
testcase_24 AC 652 ms
32,624 KB
testcase_25 AC 671 ms
32,108 KB
testcase_26 AC 98 ms
8,396 KB
testcase_27 AC 200 ms
13,992 KB
testcase_28 AC 91 ms
8,336 KB
testcase_29 AC 622 ms
31,056 KB
testcase_30 AC 203 ms
12,728 KB
testcase_31 AC 407 ms
21,548 KB
testcase_32 AC 265 ms
17,176 KB
testcase_33 AC 319 ms
17,048 KB
testcase_34 AC 599 ms
24,884 KB
testcase_35 AC 594 ms
23,916 KB
testcase_36 AC 29 ms
4,808 KB
testcase_37 AC 26 ms
4,736 KB
testcase_38 AC 650 ms
27,416 KB
testcase_39 AC 201 ms
10,872 KB
testcase_40 AC 679 ms
24,752 KB
testcase_41 AC 127 ms
8,536 KB
testcase_42 AC 327 ms
16,148 KB
testcase_43 AC 202 ms
11,428 KB
testcase_44 AC 319 ms
17,200 KB
testcase_45 AC 274 ms
15,488 KB
testcase_46 AC 141 ms
8,908 KB
testcase_47 AC 305 ms
16,144 KB
testcase_48 AC 369 ms
18,692 KB
testcase_49 AC 673 ms
24,752 KB
testcase_50 AC 484 ms
21,644 KB
testcase_51 AC 443 ms
19,532 KB
testcase_52 AC 72 ms
6,680 KB
testcase_53 AC 98 ms
8,308 KB
testcase_54 AC 487 ms
23,780 KB
testcase_55 AC 157 ms
9,180 KB
testcase_56 AC 789 ms
29,508 KB
testcase_57 AC 527 ms
20,980 KB
testcase_58 AC 991 ms
33,096 KB
testcase_59 AC 924 ms
33,228 KB
testcase_60 AC 835 ms
33,160 KB
testcase_61 AC 642 ms
33,088 KB
testcase_62 AC 562 ms
33,188 KB
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<map>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    for (auto& p : P) {
        cin >> p;
        --p;
    }
    map<int, int> pos;
    vector<vector<ll>> doubling(32, vector<ll>(N));
    rep(i, 0, N) {
        doubling[0][P[i]] = P[i] + 1;
        pos[P[i]] = i;
    }
    rep(i, 1, 32) rep(p, 0, N) {
        int next_p = P[(pos[p] + doubling[i - 1][p]) % N];
        doubling[i][p] = doubling[i - 1][p] + doubling[i - 1][next_p];
    }
    rep(i, 0, N) {
        int now = P[i];
        ll ans = pos[P[i]] + 1;
        rep(j, 0, 32) {
            if ((K >> j) & 1) {
                ans += doubling[j][now];
                now = P[(pos[now] + doubling[j][now]) % N];
            }
        }
        cout << ans << endl;
    }
    return 0;
}
0