結果

問題 No.1013 〇マス進む
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2021-08-06 03:55:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 5,151 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 110,464 KB
実行使用メモリ 66,268 KB
最終ジャッジ日時 2024-09-16 15:58:12
合計ジャッジ時間 11,993 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
17,792 KB
testcase_01 AC 26 ms
18,176 KB
testcase_02 AC 27 ms
17,920 KB
testcase_03 AC 31 ms
18,560 KB
testcase_04 AC 30 ms
18,560 KB
testcase_05 AC 30 ms
18,816 KB
testcase_06 AC 31 ms
18,944 KB
testcase_07 AC 31 ms
19,072 KB
testcase_08 AC 31 ms
18,816 KB
testcase_09 AC 31 ms
18,816 KB
testcase_10 AC 31 ms
18,816 KB
testcase_11 AC 30 ms
18,688 KB
testcase_12 AC 32 ms
19,200 KB
testcase_13 AC 36 ms
19,800 KB
testcase_14 AC 98 ms
42,532 KB
testcase_15 AC 140 ms
55,400 KB
testcase_16 AC 128 ms
53,364 KB
testcase_17 AC 84 ms
39,672 KB
testcase_18 AC 99 ms
44,332 KB
testcase_19 AC 69 ms
34,944 KB
testcase_20 AC 158 ms
61,604 KB
testcase_21 AC 82 ms
37,888 KB
testcase_22 AC 109 ms
45,192 KB
testcase_23 AC 54 ms
27,520 KB
testcase_24 AC 173 ms
63,044 KB
testcase_25 AC 162 ms
62,496 KB
testcase_26 AC 54 ms
27,392 KB
testcase_27 AC 77 ms
38,144 KB
testcase_28 AC 53 ms
27,648 KB
testcase_29 AC 161 ms
60,544 KB
testcase_30 AC 74 ms
35,968 KB
testcase_31 AC 116 ms
49,044 KB
testcase_32 AC 96 ms
41,456 KB
testcase_33 AC 101 ms
43,124 KB
testcase_34 AC 144 ms
55,088 KB
testcase_35 AC 152 ms
53,992 KB
testcase_36 AC 37 ms
20,352 KB
testcase_37 AC 37 ms
20,736 KB
testcase_38 AC 161 ms
57,844 KB
testcase_39 AC 70 ms
33,408 KB
testcase_40 AC 160 ms
55,188 KB
testcase_41 AC 56 ms
28,544 KB
testcase_42 AC 97 ms
42,068 KB
testcase_43 AC 74 ms
34,560 KB
testcase_44 AC 103 ms
43,476 KB
testcase_45 AC 93 ms
40,984 KB
testcase_46 AC 60 ms
29,568 KB
testcase_47 AC 96 ms
41,680 KB
testcase_48 AC 106 ms
45,192 KB
testcase_49 AC 160 ms
55,420 KB
testcase_50 AC 129 ms
50,332 KB
testcase_51 AC 120 ms
47,072 KB
testcase_52 AC 48 ms
24,704 KB
testcase_53 AC 54 ms
27,648 KB
testcase_54 AC 138 ms
53,696 KB
testcase_55 AC 65 ms
30,464 KB
testcase_56 AC 181 ms
60,212 KB
testcase_57 AC 139 ms
49,128 KB
testcase_58 AC 208 ms
66,264 KB
testcase_59 AC 195 ms
66,200 KB
testcase_60 AC 192 ms
66,268 KB
testcase_61 AC 163 ms
63,512 KB
testcase_62 AC 157 ms
62,756 KB
testcase_63 AC 26 ms
18,048 KB
testcase_64 AC 25 ms
17,920 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Diagnostics;
//using nint=System.Int32;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var (n,k)=sc.Tp2<int>();
		var a=sc.Ia;
		var db=new Db(n,31,true);
		for(int i = 0;i<n;i++) {
			db.Ed(i,(a[i]+i)%n);
			if(a[i]+i>=n){db.Ud(i,n);}
		}
		db.Go();
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<n;i++) {
			var e=db.Bs(i,k);
			sb.Append(e.Item1+1+e.Item2+"\n");
		}
		Console.Write(sb);
	}
}
public class Db{
	public int[][] d;
	public long[] c;
	public long[][] dp;
	public readonly int n,m,o;
	private Func<long,long,bool> comp;
	public Db(int n,bool b){
		this.n=n;
		m=(int)Log(n,2)+2;
		d=new int[m][];
		d[0]=new int[n];
		c=new long[n];
		if(b){comp=CoMax;o=-1;}
		else{comp=CoMin;o=1;}
	}
	public Db(int n,int m,bool b){
		this.n=n;
		this.m=m;
		d=new int[m][];
		d[0]=new int[n];
		c=new long[n];
		dp=new long[m][];
		dp[0]=new long[n];
		if(b){comp=CoMax;o=-1;}
		else{comp=CoMin;o=1;}
	}
	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	private bool CoMax(long x,long y){return x>y;}
	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	private bool CoMin(long x,long y){return x<y;}
	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	public void Co(int i,int x){c[i]=x;}
	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	public void Ed(int i,int x){d[0][i]=x;}
	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	public void Ud(int i,int x){dp[0][i]=x;}
	public void Go(){
		for(int i = 1;i<m;i++) {
			d[i]=new int[n];
			dp[i]=new long[n];
			for(int j = 0;j<n;j++){
				d[i][j]=d[i-1][d[i-1][j]];
				dp[i][j]=dp[i-1][j]+dp[i-1][d[i-1][j]];
			}
		}
	}
	public (int,long) Bs(int e,int x){
		long p=0;
		for(int i = m-1;i>=0;i--) {
			if((x&(1<<i))!=0){
				p+=dp[i][e];
				e=d[i][e];
			}
		}
		return (e,p);
	}
	public (int idx,int k) Bsl(int e,int x){
		var p=Bsr(e,x+o);
		if(p.idx==-1){return (e,0);}
		if(d[0][p.idx]!=p.idx){return (d[0][p.idx],p.k+1);}
		return (-1,-1);
	}
	public (int idx,int k) Bsr(int e,int x){
		if(comp(c[e],x)){return (-1,-1);}
		int g=0,f=e;
		for(int i = 0;i<m;i++) {
			if(comp(c[d[i][e]],x)){
				if(i==0){break;}
				else{
					g+=1<<(i-1);
					e=d[i-1][e];
					i=-1;
				}
			}
			else if(i==m-1){
				g+=1<<i;
				e=d[i][e];
			}
		}
		return (e,Min(g,n-f-1));
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
	public (T,T) Tp2<T>(){var s=Console.ReadLine().Split();return (Ct<T>(s[0]),Ct<T>(s[1]));}
	public (T,T,T) Tp3<T>(){var s=Console.ReadLine().Split();return (Ct<T>(s[0]),Ct<T>(s[1]),Ct<T>(s[2]));}
	public (T,T,T,T) Tp4<T>(){var s=Console.ReadLine().Split();return (Ct<T>(s[0]),Ct<T>(s[1]),Ct<T>(s[2]),Ct<T>(s[3]));}
	public (T1,T2) Tp2<T1,T2>(){var s=Console.ReadLine().Split();return (Ct<T1>(s[0]),Ct<T2>(s[1]));}
	public (T1,T1,T2) Tp3<T1,T2>(){var s=Console.ReadLine().Split();return (Ct<T1>(s[0]),Ct<T1>(s[1]),Ct<T2>(s[2]));}
	private T Ct<T>(string s){return (T)Convert.ChangeType(s,typeof(T));}
}
0