結果

問題 No.1013 〇マス進む
ユーザー tnakao0123tnakao0123
提出日時 2020-03-21 15:24:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,209 bytes
コンパイル時間 778 ms
コンパイル使用メモリ 92,244 KB
実行使用メモリ 27,436 KB
最終ジャッジ日時 2023-08-24 15:07:22
合計ジャッジ時間 6,657 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,512 KB
testcase_01 AC 2 ms
5,512 KB
testcase_02 AC 2 ms
5,544 KB
testcase_03 AC 2 ms
5,516 KB
testcase_04 AC 2 ms
5,532 KB
testcase_05 AC 2 ms
5,592 KB
testcase_06 AC 2 ms
5,564 KB
testcase_07 AC 2 ms
5,600 KB
testcase_08 AC 2 ms
5,640 KB
testcase_09 AC 2 ms
5,592 KB
testcase_10 AC 2 ms
5,592 KB
testcase_11 AC 2 ms
5,628 KB
testcase_12 AC 2 ms
5,764 KB
testcase_13 AC 4 ms
5,976 KB
testcase_14 AC 33 ms
18,212 KB
testcase_15 AC 59 ms
26,360 KB
testcase_16 AC 51 ms
24,220 KB
testcase_17 AC 29 ms
18,040 KB
testcase_18 AC 38 ms
18,008 KB
testcase_19 AC 21 ms
13,824 KB
testcase_20 AC 72 ms
26,680 KB
testcase_21 AC 26 ms
16,068 KB
testcase_22 AC 39 ms
20,072 KB
testcase_23 AC 12 ms
9,620 KB
testcase_24 AC 73 ms
27,240 KB
testcase_25 AC 72 ms
26,788 KB
testcase_26 AC 12 ms
9,708 KB
testcase_27 AC 24 ms
15,884 KB
testcase_28 AC 13 ms
9,720 KB
testcase_29 AC 67 ms
26,512 KB
testcase_30 AC 24 ms
13,972 KB
testcase_31 AC 44 ms
22,276 KB
testcase_32 AC 31 ms
18,000 KB
testcase_33 AC 33 ms
17,960 KB
testcase_34 AC 60 ms
24,244 KB
testcase_35 AC 57 ms
22,164 KB
testcase_36 AC 5 ms
6,060 KB
testcase_37 AC 4 ms
6,148 KB
testcase_38 AC 62 ms
26,468 KB
testcase_39 AC 22 ms
13,804 KB
testcase_40 AC 66 ms
24,504 KB
testcase_41 AC 15 ms
11,716 KB
testcase_42 AC 34 ms
17,988 KB
testcase_43 AC 21 ms
13,888 KB
testcase_44 AC 35 ms
18,000 KB
testcase_45 AC 30 ms
17,952 KB
testcase_46 AC 16 ms
11,748 KB
testcase_47 AC 33 ms
18,044 KB
testcase_48 AC 39 ms
18,012 KB
testcase_49 AC 66 ms
24,284 KB
testcase_50 AC 48 ms
22,120 KB
testcase_51 AC 43 ms
20,048 KB
testcase_52 AC 10 ms
9,128 KB
testcase_53 AC 12 ms
9,492 KB
testcase_54 AC 46 ms
22,164 KB
testcase_55 AC 18 ms
11,956 KB
testcase_56 AC 72 ms
26,348 KB
testcase_57 AC 53 ms
22,408 KB
testcase_58 AC 101 ms
27,288 KB
testcase_59 AC 90 ms
27,436 KB
testcase_60 AC 76 ms
27,312 KB
testcase_61 AC 68 ms
27,312 KB
testcase_62 AC 62 ms
27,316 KB
testcase_63 AC 2 ms
5,524 KB
testcase_64 AC 2 ms
5,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1013.cc:  No.1013 〇マス進む - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int BN = 30;

/* typedef */

typedef long long ll;

/* global variables */

int ps[MAX_N], ts[MAX_N][BN], rs[MAX_N][BN];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  for (int i = 0; i < n; i++) scanf("%d", ps + i);

  for (int i = 0; i < n; i++) {
    int d = i + ps[i];
    ts[i][0] = d % n;
    rs[i][0] = d / n;
  }

  for (int j = 0; j + 1 < BN; j++)
    for (int i = 0; i < n; i++) {
      ts[i][j + 1] = ts[ts[i][j]][j];
      rs[i][j + 1] = rs[i][j] + rs[ts[i][j]][j];
    }

  for (int i = 0; i < n; i++) {
    int u = i, r = 0;
    for (int j = 0, bj = 1; j < BN; j++, bj <<= 1)
      if (k & bj) {
	r += rs[u][j];
	u = ts[u][j];
      }

    printf("%lld\n", (ll)r * n + u + 1);
  }
  return 0;
}
0