結果

問題 No.78 クジ付きアイスバー
ユーザー mbanmban
提出日時 2017-02-18 04:07:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 68 ms / 5,000 ms
コード長 3,061 bytes
コンパイル時間 3,708 ms
コンパイル使用メモリ 109,340 KB
実行使用メモリ 25,768 KB
最終ジャッジ日時 2023-08-28 18:34:59
合計ジャッジ時間 6,686 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
23,776 KB
testcase_01 AC 66 ms
21,736 KB
testcase_02 AC 65 ms
21,744 KB
testcase_03 AC 66 ms
21,740 KB
testcase_04 AC 66 ms
21,728 KB
testcase_05 AC 66 ms
21,868 KB
testcase_06 AC 66 ms
23,728 KB
testcase_07 AC 66 ms
23,708 KB
testcase_08 AC 65 ms
21,676 KB
testcase_09 AC 64 ms
21,656 KB
testcase_10 AC 64 ms
23,780 KB
testcase_11 AC 65 ms
21,856 KB
testcase_12 AC 64 ms
21,736 KB
testcase_13 AC 65 ms
21,616 KB
testcase_14 AC 64 ms
21,844 KB
testcase_15 AC 65 ms
23,552 KB
testcase_16 AC 64 ms
21,788 KB
testcase_17 AC 64 ms
19,588 KB
testcase_18 AC 64 ms
23,652 KB
testcase_19 AC 65 ms
23,688 KB
testcase_20 AC 64 ms
21,712 KB
testcase_21 AC 66 ms
23,768 KB
testcase_22 AC 67 ms
23,696 KB
testcase_23 AC 66 ms
21,736 KB
testcase_24 AC 64 ms
21,728 KB
testcase_25 AC 65 ms
23,636 KB
testcase_26 AC 64 ms
21,744 KB
testcase_27 AC 66 ms
21,660 KB
testcase_28 AC 63 ms
23,704 KB
testcase_29 AC 64 ms
21,804 KB
testcase_30 AC 65 ms
23,772 KB
testcase_31 AC 64 ms
23,744 KB
testcase_32 AC 64 ms
21,740 KB
testcase_33 AC 68 ms
25,768 KB
testcase_34 AC 65 ms
21,572 KB
testcase_35 AC 64 ms
21,708 KB
testcase_36 AC 64 ms
23,668 KB
testcase_37 AC 65 ms
23,848 KB
testcase_38 AC 63 ms
19,664 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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

public class Scanner
{
    private StreamReader Sr;

    private string[] S;
    private int Index;
    private const char Separator = ' ';

    public Scanner(Stream source)
    {
        Index = 0;
        S = new string[0];
        Sr = new StreamReader(source);
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public decimal NextDecimal()
    {
        return decimal.Parse(Next());
    }
    public string[] StringArray(int index = 0)
    {
        Next();
        Index = S.Length;
        return S.Skip(index).ToArray();
    }
    public int[] IntArray(int index = 0)
    {
        return StringArray(index).Select(int.Parse).ToArray();
    }
    public long[] LongArray(int index = 0)
    {
        return StringArray(index).Select(long.Parse).ToArray();
    }
    public bool EndOfStream
    {
        get { return Sr.EndOfStream; }
    }
}

public class Magatro
{
    private Scanner Cin;

    private int N, K;
    private int[] S;
    private void Scan()
    {
        Cin = new Scanner(Console.OpenStandardInput());
        N = Cin.NextInt();
        K = Cin.NextInt();
        S = Cin.Next().ToArray().Select(c => int.Parse(c.ToString())).ToArray();
    }
    //なぜこれでいいのか理解してない
    public void Solve()
    {
        Scan();
        int sum = S.Sum();
        if (N <= sum)
        {
            int p = 0;
            int ans = 0;
            for(int i = 0; i < N && i < K; i++)
            {
                 p--;
                while (p < 0)
                {
                    ans++;
                    p++;
                }
                p += S[i];
            }
            Console.WriteLine(ans);
        }
        else
        {
            int ans = K;
            ans -= K / N * sum;
            for (int i = 0; i < K%N; i++)
            {
                ans -= S[i];
            }
            int w = 0;
            int t = 0;
            int c = 0;
            for (int i = K-1; i >=0&&c<100 ; i--)
            {
                t += S[i % N];
                if (t > w)
                {
                    w = t;
                    c = 0;
                }
                t--;
                c++;
            }
            ans += w;
            Console.WriteLine(ans);
        }
    }
}
0