結果

問題 No.1013 〇マス進む
ユーザー 37zigen
提出日時 2019-12-07 22:33:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,260 ms / 2,000 ms
コード長 1,055 bytes
コンパイル時間 4,902 ms
コンパイル使用メモリ 77,696 KB
実行使用メモリ 139,076 KB
最終ジャッジ日時 2024-12-26 13:24:38
合計ジャッジ時間 51,226 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 62
権限があれば一括ダウンロードができます

ソースコード

diff #

//制約侵害のcheck

import java.util.*;
import java.math.*;
import java.io.*;

class Main
{
	public static void main(String[] args)
	{
		new Main().run();
	}
	
	void run(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long K=sc.nextLong();
		if(!(1<=N&&N<=1e5&&1<=K&&K<=1e9))throw new AssertionError();
		int[] P=new int[N];
		long[][] add=new long[63][N];
		boolean[] vis=new boolean[N];
		for(int i=0;i<N;++i){
			P[i]=sc.nextInt();
			add[0][i]=P[i];
			vis[P[i]-1]=true;
		}
		boolean check=true;
		for(int i=0;i<N;++i)check&=vis[i];
		if(!check)throw new AssertionError();
		for(int i=0;i+1<30;++i){
			for(int j=0;j<N;++j){
				add[i+1][j]=add[i][j]+add[i][(int)((j+add[i][j])%N)];
			}
		}
		PrintWriter pw=new PrintWriter(System.out);
		for(int i=0;i<N;++i){
			long res=K;
			long cur=i;
			for(int shift=0;shift<30;++shift){
				if((res>>shift)%2==1)
					cur=cur+add[shift][(int)(cur%N)];
			}
			pw.println(cur+1);
		}
		pw.close();
	}
	
	void tr(Object...objects){
		System.out.println(Arrays.deepToString(objects));
	}
}
0