結果

問題 No.78 クジ付きアイスバー
ユーザー 14番14番
提出日時 2016-04-09 12:33:45
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,752 bytes
コンパイル時間 2,237 ms
コンパイル使用メモリ 105,856 KB
実行使用メモリ 35,072 KB
最終ジャッジ日時 2024-04-16 06:07:39
合計ジャッジ時間 14,191 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
35,072 KB
testcase_01 AC 26 ms
18,304 KB
testcase_02 AC 27 ms
18,432 KB
testcase_03 AC 27 ms
17,920 KB
testcase_04 AC 27 ms
18,048 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.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


";
}

0