結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー |
![]() |
提出日時 | 2016-05-03 12:04:02 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,850 bytes |
コンパイル時間 | 1,171 ms |
コンパイル使用メモリ | 116,200 KB |
実行使用メモリ | 29,000 KB |
最終ジャッジ日時 | 2024-10-05 03:27:28 |
合計ジャッジ時間 | 3,042 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
24,876 KB |
testcase_01 | AC | 30 ms
24,912 KB |
testcase_02 | AC | 31 ms
24,756 KB |
testcase_03 | AC | 32 ms
26,964 KB |
testcase_04 | AC | 31 ms
22,712 KB |
testcase_05 | AC | 31 ms
24,620 KB |
testcase_06 | AC | 32 ms
26,976 KB |
testcase_07 | AC | 32 ms
26,704 KB |
testcase_08 | AC | 31 ms
24,884 KB |
testcase_09 | AC | 30 ms
22,964 KB |
testcase_10 | AC | 31 ms
24,756 KB |
testcase_11 | AC | 31 ms
25,136 KB |
testcase_12 | AC | 30 ms
24,912 KB |
testcase_13 | AC | 33 ms
26,576 KB |
testcase_14 | AC | 31 ms
26,576 KB |
testcase_15 | AC | 30 ms
26,832 KB |
testcase_16 | AC | 31 ms
26,696 KB |
testcase_17 | AC | 31 ms
26,956 KB |
testcase_18 | AC | 31 ms
26,956 KB |
testcase_19 | AC | 31 ms
26,580 KB |
testcase_20 | AC | 30 ms
24,660 KB |
testcase_21 | AC | 31 ms
24,908 KB |
testcase_22 | AC | 30 ms
24,784 KB |
testcase_23 | WA | - |
testcase_24 | AC | 33 ms
24,884 KB |
testcase_25 | WA | - |
testcase_26 | AC | 31 ms
24,748 KB |
testcase_27 | AC | 32 ms
25,008 KB |
testcase_28 | WA | - |
testcase_29 | AC | 31 ms
24,880 KB |
コンパイルメッセージ
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; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; long temotiCount = long.Parse(Reader.ReadLine()); int boxCount = int.Parse(Reader.ReadLine()); List<long> boxList = new List<long>(); Dictionary<long, int> dic = new Dictionary<long, int>(); long total = 0; for(int i=0; i<boxCount; i++) { long val = long.Parse(Reader.ReadLine()); if(dic.ContainsKey(val)) { dic[val]++; } else { dic.Add(val, 1); } boxList.Add(val); total += val; } long heikin = total / boxCount; if(Math.Abs(total - (heikin + 1) * boxCount) < Math.Abs(total - heikin * boxCount)) { heikin++; } while ((heikin * boxCount - total) > temotiCount) { heikin--; } // 最頻値 List<long> modeList = new List<long>(); int prevCnt = dic.Max(a=>a.Value); dic.ToList().ForEach((a)=>{ if(a.Value == prevCnt && total + temotiCount >= a.Key * boxCount) { modeList.Add(a.Key); } }); long ans = long.MaxValue; long tmp = 0; boxList.ForEach((a)=>{ tmp += Math.Abs(a - heikin); }); ans = Math.Min(ans, tmp); modeList.ForEach((a)=>{ tmp = 0; boxList.ForEach((b)=>{ tmp+=Math.Abs(a-b); }); ans = Math.Min(ans, tmp); }); Console.WriteLine(ans); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 0 2 0 1 "; 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(); } }