結果

問題 No.78 クジ付きアイスバー
ユーザー 14番14番
提出日時 2016-07-17 19:09:15
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 3,425 bytes
コンパイル時間 2,402 ms
コンパイル使用メモリ 113,992 KB
実行使用メモリ 29,528 KB
最終ジャッジ日時 2024-04-25 14:48:39
合計ジャッジ時間 3,035 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,568 KB
testcase_01 AC 31 ms
25,604 KB
testcase_02 AC 32 ms
25,644 KB
testcase_03 AC 31 ms
25,348 KB
testcase_04 AC 33 ms
25,600 KB
testcase_05 AC 31 ms
25,476 KB
testcase_06 AC 29 ms
25,352 KB
testcase_07 AC 30 ms
27,520 KB
testcase_08 AC 29 ms
27,608 KB
testcase_09 AC 28 ms
25,304 KB
testcase_10 AC 29 ms
27,356 KB
testcase_11 AC 29 ms
29,528 KB
testcase_12 AC 32 ms
25,520 KB
testcase_13 AC 30 ms
25,312 KB
testcase_14 AC 30 ms
25,140 KB
testcase_15 AC 29 ms
23,352 KB
testcase_16 AC 31 ms
25,736 KB
testcase_17 AC 30 ms
27,492 KB
testcase_18 AC 31 ms
25,348 KB
testcase_19 AC 32 ms
25,736 KB
testcase_20 AC 31 ms
25,648 KB
testcase_21 AC 32 ms
27,776 KB
testcase_22 AC 32 ms
25,612 KB
testcase_23 AC 33 ms
27,652 KB
testcase_24 AC 33 ms
25,728 KB
testcase_25 AC 30 ms
24,960 KB
testcase_26 AC 33 ms
25,468 KB
testcase_27 AC 32 ms
27,632 KB
testcase_28 AC 30 ms
27,512 KB
testcase_29 AC 32 ms
25,732 KB
testcase_30 AC 32 ms
27,532 KB
testcase_31 AC 30 ms
23,732 KB
testcase_32 AC 31 ms
25,600 KB
testcase_33 AC 31 ms
25,860 KB
testcase_34 AC 34 ms
27,660 KB
testcase_35 AC 32 ms
25,592 KB
testcase_36 AC 32 ms
27,648 KB
testcase_37 AC 32 ms
25,480 KB
testcase_38 AC 29 ms
25,560 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.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        long[] inpt = Reader.ReadLine().Split(' ').Select(a=>long.Parse(a)).ToArray();
        int countInBox = (int)inpt[0];
        long mustEat = inpt[1];
        this.IceList = Reader.ReadLine().Select(a=>int.Parse(a.ToString())).ToArray();
        long ans = 0;
        if(this.IceList.Sum(a=>a) > this.IceList.Length) {
            ans = this.GetAns2(mustEat, 0);
        } else {
            ans = this.GetAns(0, 0, mustEat, 0);
        }
        Console.WriteLine(ans);

    }

    int[] IceList;

    private long GetAns(long buyCount, long getCount, long musEat, long charge) {
        if(charge >= musEat - getCount) {
            return buyCount;
        }
        long subBuy = buyCount;
        long subGet = getCount;
        long subCharge = charge;

        if(dic.ContainsKey(charge)) {
            long buyTemp = buyCount - this.dic[charge].BuyCount;
            long getTemp = getCount - this.dic[charge].GetCount;

            long remain = musEat - getCount;
            if(remain > getTemp) {
                long mul  = remain / getTemp;
                subBuy += buyTemp * mul;
                subGet += getTemp * mul;
            }
        } else {
            dic.Add(charge, new HakoState(buyCount, getCount));
        }
        for(int i=0; i<this.IceList.Length && subGet<musEat; i++) {
            if(subCharge > 0) {
                subCharge--;
            } else {
                subBuy++;
            }
            subGet++;
            subCharge+=this.IceList[i];
        }
        if(subGet < musEat) {
            subBuy = this.GetAns(subBuy, subGet, musEat, subCharge);
        }
        return subBuy;
    }
    private long GetAns2(long remain, long charge) {
        if(remain <= charge) {
            return 0;
        }
        if(charge >=IceList.Length) {
            return 0;
        }
        long ans = 0;
        long subRemain = remain;
        long subCharge = charge;
        for(int i=0; i<IceList.Length && i<remain; i++) {
            if(subCharge > 0) {
                subCharge--;
                subRemain--;
            } else {
                ans++;
                subRemain--;
            }
            subCharge+=IceList[i];
        }
        ans += this.GetAns2(subRemain, subCharge);
        return ans;
    }

    private Dictionary<long, HakoState> dic = new Dictionary<long, HakoState>();
    
    public class HakoState {
        public long BuyCount;
        public long GetCount;

        public HakoState(long buy, long gt) {
            this.BuyCount = buy;
            this.GetCount = gt;
        }
    }

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"

7 24
2000102


 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }

    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0