結果
| 問題 |
No.21 平均の差
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-04-03 01:00:25 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,399 bytes |
| コンパイル時間 | 2,829 ms |
| コンパイル使用メモリ | 106,496 KB |
| 実行使用メモリ | 40,960 KB |
| 最終ジャッジ日時 | 2024-10-02 12:31:59 |
| 合計ジャッジ時間 | 9,801 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 TLE * 1 -- * 5 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
14番