結果

問題 No.1013 〇マス進む
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2021-08-06 03:55:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 5,151 bytes
コンパイル時間 3,061 ms
コンパイル使用メモリ 107,404 KB
実行使用メモリ 68,636 KB
最終ジャッジ日時 2023-10-14 22:18:42
合計ジャッジ時間 20,508 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
20,980 KB
testcase_01 AC 61 ms
20,796 KB
testcase_02 AC 59 ms
20,752 KB
testcase_03 AC 66 ms
22,976 KB
testcase_04 AC 66 ms
18,852 KB
testcase_05 AC 67 ms
18,856 KB
testcase_06 AC 66 ms
22,944 KB
testcase_07 AC 66 ms
21,044 KB
testcase_08 AC 65 ms
20,896 KB
testcase_09 AC 66 ms
20,908 KB
testcase_10 AC 64 ms
20,952 KB
testcase_11 AC 66 ms
19,004 KB
testcase_12 AC 68 ms
23,000 KB
testcase_13 AC 73 ms
22,124 KB
testcase_14 AC 127 ms
47,392 KB
testcase_15 AC 170 ms
59,620 KB
testcase_16 AC 152 ms
57,756 KB
testcase_17 AC 115 ms
44,804 KB
testcase_18 AC 131 ms
44,636 KB
testcase_19 AC 106 ms
38,232 KB
testcase_20 AC 188 ms
62,100 KB
testcase_21 AC 116 ms
42,320 KB
testcase_22 AC 135 ms
49,440 KB
testcase_23 AC 85 ms
28,168 KB
testcase_24 AC 193 ms
67,552 KB
testcase_25 AC 187 ms
66,864 KB
testcase_26 AC 85 ms
28,348 KB
testcase_27 AC 110 ms
41,132 KB
testcase_28 AC 87 ms
28,244 KB
testcase_29 AC 183 ms
65,232 KB
testcase_30 AC 107 ms
37,140 KB
testcase_31 AC 148 ms
51,212 KB
testcase_32 AC 124 ms
44,524 KB
testcase_33 AC 128 ms
45,580 KB
testcase_34 AC 169 ms
57,672 KB
testcase_35 AC 179 ms
56,248 KB
testcase_36 AC 75 ms
24,816 KB
testcase_37 AC 74 ms
22,556 KB
testcase_38 AC 188 ms
60,008 KB
testcase_39 AC 105 ms
30,176 KB
testcase_40 AC 191 ms
51,668 KB
testcase_41 AC 93 ms
31,000 KB
testcase_42 AC 133 ms
44,136 KB
testcase_43 AC 103 ms
35,748 KB
testcase_44 AC 131 ms
47,876 KB
testcase_45 AC 123 ms
45,492 KB
testcase_46 AC 95 ms
31,632 KB
testcase_47 AC 126 ms
46,216 KB
testcase_48 AC 138 ms
47,888 KB
testcase_49 AC 181 ms
59,748 KB
testcase_50 AC 160 ms
54,820 KB
testcase_51 AC 151 ms
49,648 KB
testcase_52 AC 80 ms
25,732 KB
testcase_53 AC 88 ms
29,940 KB
testcase_54 AC 167 ms
56,332 KB
testcase_55 AC 97 ms
32,140 KB
testcase_56 AC 202 ms
62,612 KB
testcase_57 AC 167 ms
45,544 KB
testcase_58 AC 235 ms
62,460 KB
testcase_59 AC 220 ms
62,596 KB
testcase_60 AC 227 ms
68,636 KB
testcase_61 AC 204 ms
65,824 KB
testcase_62 AC 192 ms
65,436 KB
testcase_63 AC 57 ms
14,856 KB
testcase_64 AC 59 ms
14,808 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