結果

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

ソースコード

diff #

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

const int MAX_LOG=30;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K; cin >> N >> K;
    vector<int> P(N);
    for (int i=0;i<N;++i) cin >> P[i];
    vector<vector<pair<ll,ll>>> doubling(MAX_LOG,vector<pair<ll,ll>>(N));
    for (int i=0;i<N;++i) doubling[0][i]={(i+P[i])%N,(i+P[i])/N};
    for (int j=0;j<MAX_LOG-1;++j)
        for (int i=0;i<N;++i)
            doubling[j+1][i]={doubling[j][doubling[j][i].first].first,doubling[j][i].second+doubling[j][doubling[j][i].first].second};
    for (int i=0;i<N;++i){
        ll now=i,cnt=0;
        for (int j=0;j<MAX_LOG;++j) if (K&1<<j){
            cnt+=doubling[j][now].second;
            now=doubling[j][now].first;
        }
        cout << now+1+cnt*N << '\n';
    }
}
0