結果
問題 |
No.78 クジ付きアイスバー
|
ユーザー |
![]() |
提出日時 | 2016-04-09 12:33:45 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,752 bytes |
コンパイル時間 | 2,637 ms |
コンパイル使用メモリ | 111,692 KB |
実行使用メモリ | 26,360 KB |
最終ジャッジ日時 | 2024-10-06 19:06:36 |
合計ジャッジ時間 | 13,140 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 1 WA * 1 TLE * 1 -- * 32 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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<tmp.Length; i++) { this.Map[i] = int.Parse(tmp[i].ToString()); } long ans = this.GetAns(0, this.MustCount); Console.WriteLine(ans); } Dictionary<int, IceBox> dic = new Dictionary<int, IceBox>(); 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<inpt.Length; i++) { string item = inpt[i]; if(mustTrim) { item = item.Trim(); } ret[i] = int.Parse(item); } return ret; } private static string initStr = @" 2 5 01 "; }