結果

問題 No.576 E869120 and Rings
ユーザー sekiya9311sekiya9311
提出日時 2017-10-13 22:43:36
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,799 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 107,520 KB
実行使用メモリ 24,192 KB
最終ジャッジ日時 2024-04-28 17:37:33
合計ジャッジ時間 11,891 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 387 ms
24,064 KB
testcase_09 WA -
testcase_10 AC 390 ms
24,192 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 464 ms
23,424 KB
testcase_15 AC 471 ms
24,192 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 388 ms
24,064 KB
testcase_20 AC 404 ms
24,064 KB
testcase_21 WA -
testcase_22 AC 28 ms
18,688 KB
testcase_23 AC 28 ms
18,816 KB
testcase_24 AC 27 ms
18,176 KB
testcase_25 AC 28 ms
18,816 KB
testcase_26 AC 27 ms
17,920 KB
testcase_27 AC 28 ms
18,816 KB
testcase_28 AC 27 ms
18,560 KB
testcase_29 AC 28 ms
18,816 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.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingContest
{
    class MainClass
    {
        Scanner sc;
        static void Main(string[] args)
        {
            new MainClass().Solve();
        }

        void Solve()
        {
#if DEBUG
            string backPath = "..";
            char dirSep = System.IO.Path.DirectorySeparatorChar;
            string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
            sc = new Scanner(new System.IO.StreamReader(inFilePath));
#else
            sc = new Scanner();
#endif

            N = sc.NextInt;
            K = sc.NextInt;
            string s = sc.Next;
            a = new int[N * 2];
            for (int i = 0; i < N; i++)
            {
                a[i] = a[N + i] = s[i] - '0';
            }
            int high = N, low = K;
            while (high - low > 100)
            {
                int mid1 = (high + (low << 1)) / 3;
                int mid2 = ((high << 1) + low) / 3;
                if (mid1 <= mid2)
                {
                    high = mid2;
                }
                else
                {
                    low = mid1;
                }
            }
            double ans = 0;
            for (int i = low; i <= high; i++)
            {
                ans = Math.Max(ans, calc(i));
            }
            Write(ans);
        }
        double calc(int cnt)
        {
           // Console.Error.WriteLine("cnt = {0}", cnt);
            double ret = 0;
            int nowSum = 0;
            for (int i = 0; i < cnt; i++)
            {
                nowSum += a[i];
            }
            ret = Math.Max(ret, 1.0 * nowSum / cnt);
            for (int i = cnt; i < N * 2; i++)
            {
                //Console.Error.WriteLine("({0}, {1})", i - cnt + 1, i + 1);
                nowSum -= a[i - cnt];
                nowSum += a[i];
                ret = Math.Max(ret, 1.0 * nowSum / cnt);
            }
            return ret;
        }
        int N, K;
        int[] a;

        void Write(object val)
        {
            Console.WriteLine(val.ToString());
        }
        void Write(string format, params object[] vals)
        {
            Console.WriteLine(format, vals);
        }
    }
    
    class Scanner
    {
        Queue<String> buffer;
        char[] sep;
        System.IO.TextReader reader;
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.buffer.Count == 0 && this.reader.Peek() >= 0)
            {
                string[] sreArray = this.reader.ReadLine().Split(this.sep);
                foreach (String elStr in sreArray)
                {
                    this.buffer.Enqueue(elStr);
                }
            }
        }

        public String Next
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }
        public bool IsEmpty
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}
0