using System; using System.Collections.Generic; using System.Text; public class Program { public void Proc(){ Reader.IsDebug = false; string[] inpt = Reader.ReadLine().Split(' '); this.InBox = int.Parse(inpt[0]); this.MustCount = int.Parse(inpt[1]); string tmp = Reader.ReadLine(); this.Map = new int[this.InBox]; for(int i=0; i dic = new Dictionary(); public long GetAns(int startIdx, long mustBuy) { long cnt = 0; long ans = 0; int idx = startIdx; while (cnt < mustBuy) { ans++; long addCount = 0; int subIdx = idx; while (cnt + addCount < mustBuy) { if(dic.ContainsKey(subIdx)) { IceBox bx = dic[subIdx]; addCount += bx.AddIce; subIdx = bx.NextIndex; break; } if(this.Map[subIdx] == 0) { addCount++; subIdx++; break; } else if(this.Map[subIdx] == 1) { addCount+=1; subIdx+=1; } else { int tmp = subIdx + 1; if(tmp >= this.Map.Length) { tmp -= this.Map.Length; } if(this.Map[tmp] == 2) { addCount+=3; subIdx += 3; } else { addCount+=2; subIdx+=2; } } if(subIdx >= Map.Length) { subIdx -= this.Map.Length; } } if(subIdx >= Map.Length) { subIdx -= this.Map.Length; } if(!dic.ContainsKey(idx)) { IceBox bx = new IceBox(); bx.AddIce = addCount; bx.BuyAt = idx; bx.NextIndex = subIdx; dic.Add(idx, bx); } cnt+=addCount; idx = subIdx; } return ans; } private int[] Map; private int InBox = 0; private long MustCount = 0; public class IceBox { public int BuyAt = 0; public long AddIce = 0; public int NextIndex = 0; } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } } class Reader { public static bool IsDebug = true; private static System.IO.StringReader sr; public static string ReadLine() { if(IsDebug) { if(sr == null) { sr = new System.IO.StringReader(initStr.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ', bool mustTrim = false) { string src = ReadLine(); if(mustTrim) { src = src.Trim(); } string[] inpt = src.Split(delimiter); int[] ret = new int[inpt.Length]; for(int i=0; i