結果

問題 No.21 平均の差
ユーザー 14番14番
提出日時 2016-04-03 01:00:25
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,399 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 113,616 KB
実行使用メモリ 55,404 KB
最終ジャッジ日時 2024-04-10 10:41:10
合計ジャッジ時間 7,991 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
55,404 KB
testcase_01 AC 86 ms
27,980 KB
testcase_02 AC 274 ms
28,096 KB
testcase_03 AC 25 ms
23,980 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;

        int numCount = int.Parse(Reader.ReadLine());
        this.GroupCount = int.Parse(Reader.ReadLine());

        for (int i = 0; i < numCount; i++)
        {
            this.NumList.Add(int.Parse(Reader.ReadLine()));
        }
        List<int>[] tmp = new List<int>[GroupCount];
        for (int i = 0; i < GroupCount; i++)
        {
            tmp[i] = new List<int>();
        }
        double ans = this.GetAns(0, tmp);
        Console.WriteLine(((int)ans).ToString());

    }


    private int GroupCount = 0;
    List<int> NumList = new List<int>();

    private double GetAns(int idx, List<int>[] grp)
    {
        if (idx == NumList.Count)
        {
            double min = double.MaxValue;
            double max = double.MinValue;
            for (int i = 0; i < GroupCount; i++)
            {
                if (grp[i].Count == 0)
                {
                    return -1;
                }
                else
                {
                    double total = 0;
                    for (int j = 0; j < grp[i].Count; j++)
                    {
                        total += grp[i][j];
                    }
                    total = total / grp[i].Count;
                    min = Math.Min(min, total);
                    max = Math.Max(max, total);
                }
            }
            return Math.Ceiling(max - min);
        }
        else
        {
            double ans = -1;
            for (int i = 0; i < GroupCount; i++)
            {
                List<int>[] subList = new List<int>[GroupCount];
                for (int j = 0; j < GroupCount; j++)
                {
                    List<int> subGruup = new List<int>();
                    subGruup.AddRange(grp[j]);
                    subList[j] = subGruup;
                }
                subList[i].Add(this.NumList[idx]);
                double ret = this.GetAns(idx + 1, subList);
                if (ret >= 0)
                {
                    ans = Math.Max(ans, ret);
                }
            }
            return ans;

        }
    }

    


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"
 
8
4
329
980
656
738
739
542
873
501



 
";
        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();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0