結果

問題 No.1013 〇マス進む
ユーザー 0w10w1
提出日時 2020-11-13 10:17:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 2,761 ms
コンパイル使用メモリ 206,240 KB
実行使用メモリ 40,216 KB
最終ジャッジ日時 2023-09-30 01:57:07
合計ジャッジ時間 12,106 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,412 KB
testcase_14 AC 29 ms
20,916 KB
testcase_15 AC 51 ms
31,652 KB
testcase_16 AC 46 ms
29,388 KB
testcase_17 AC 26 ms
18,636 KB
testcase_18 AC 32 ms
21,728 KB
testcase_19 AC 19 ms
14,348 KB
testcase_20 AC 66 ms
37,972 KB
testcase_21 AC 24 ms
17,348 KB
testcase_22 AC 33 ms
22,616 KB
testcase_23 AC 11 ms
9,368 KB
testcase_24 AC 64 ms
39,136 KB
testcase_25 AC 62 ms
38,360 KB
testcase_26 AC 12 ms
9,628 KB
testcase_27 AC 20 ms
16,424 KB
testcase_28 AC 10 ms
9,484 KB
testcase_29 AC 59 ms
37,252 KB
testcase_30 AC 20 ms
14,856 KB
testcase_31 AC 39 ms
25,696 KB
testcase_32 AC 27 ms
20,280 KB
testcase_33 AC 30 ms
20,028 KB
testcase_34 AC 58 ms
30,028 KB
testcase_35 AC 69 ms
28,436 KB
testcase_36 AC 4 ms
4,956 KB
testcase_37 AC 4 ms
4,680 KB
testcase_38 AC 65 ms
32,812 KB
testcase_39 AC 19 ms
12,788 KB
testcase_40 AC 79 ms
29,936 KB
testcase_41 AC 14 ms
9,636 KB
testcase_42 AC 31 ms
19,288 KB
testcase_43 AC 21 ms
13,760 KB
testcase_44 AC 33 ms
20,240 KB
testcase_45 AC 29 ms
18,184 KB
testcase_46 AC 15 ms
10,304 KB
testcase_47 AC 28 ms
19,160 KB
testcase_48 AC 36 ms
22,044 KB
testcase_49 AC 76 ms
29,772 KB
testcase_50 AC 48 ms
25,880 KB
testcase_51 AC 45 ms
23,216 KB
testcase_52 AC 9 ms
6,952 KB
testcase_53 AC 12 ms
8,768 KB
testcase_54 AC 48 ms
28,104 KB
testcase_55 AC 17 ms
10,620 KB
testcase_56 AC 75 ms
34,860 KB
testcase_57 AC 65 ms
24,940 KB
testcase_58 AC 110 ms
40,092 KB
testcase_59 AC 87 ms
40,008 KB
testcase_60 AC 92 ms
40,052 KB
testcase_61 AC 65 ms
39,932 KB
testcase_62 AC 63 ms
40,216 KB
testcase_63 AC 2 ms
4,380 KB
testcase_64 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N, K; {
    cin >> N >> K;
  }

  vector<int> P(N); {
    for (int i = 0; i < N; ++i) cin >> P[i];
  }

  vector<int> rp(N + 1); {
    for (int i = 0; i < N; ++i) rp[P[i]] = i + 1;
  }

  vector<vector<int>> pf(30, vector<int>(N + 1));
  vector<vector<int64_t>> pp(30, vector<int64_t>(N + 1)); {
    for (int i = 0; i < N; ++i) pf[0][P[i]] = i + P[i] >= N;
    for (int i = 0; i < N; ++i) pp[0][P[i]] = P[(i + P[i]) % N];
    for (int i = 0; i < 29; ++i) {
      for (int u = 1; u <= N; ++u) {
        pf[i + 1][u] = pf[i][u] + pf[i][pp[i][u]];
        pp[i + 1][u] = pp[i][pp[i][u]];
      }
    }
  }

  for (int p : P) {
    int64_t c = 0;
    int r = p;
    for (int i = 29, k = K; k; --i) if (k >= 1 << i) {
      k -= 1 << i;
      c += (int64_t) N * pf[i][r];
      r = pp[i][r];
    }
    cout << (c + rp[r]) << "\n";
  }
}

0