結果

問題 No.1013 〇マス進む
ユーザー Y17Y17
提出日時 2020-03-20 22:19:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 169,972 KB
実行使用メモリ 82,440 KB
最終ジャッジ日時 2024-12-15 06:29:54
合計ジャッジ時間 10,892 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 62
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n, k;
int p[100010];

pair<int, int> Next[50][100010] = {};

signed main(){
	cin >> n >> k;

	for(int i = 0;i < n;i++){
		cin >> p[i];
	}

	for(int i = 0;i < n;i++){
		Next[0][i] = {(i+p[i]) % n, (i+p[i]) >= n ? 1 : 0};
	}

	for(int b = 1;b < 50;b++){
		for(int i = 0;i <= n;i++){
			pair<int, int> x = Next[b-1][i];
			pair<int, int> y = Next[b-1][x.first];
			pair<int, int> ans = {y.first, x.second + y.second};
			Next[b][i] = ans; 
		}
	}

	for(int i = 0;i < n;i++){
		int ans = 0;
		int now = i;
		for(int b = 0;b < 50;b++){
			if(k & (1ll << b)){
				ans += Next[b][now].second;
				now = Next[b][now].first;
			}
		}
		cout << ans*n + now + 1 << endl;
	}

	return 0;
}
0