結果

問題 No.609 Noelちゃんと星々
ユーザー bluemeganebluemegane
提出日時 2018-10-08 19:29:54
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 3,137 ms
コンパイル使用メモリ 114,468 KB
実行使用メモリ 42,752 KB
最終ジャッジ日時 2024-04-20 18:45:06
合計ジャッジ時間 5,763 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
41,216 KB
testcase_01 AC 90 ms
28,416 KB
testcase_02 AC 69 ms
25,216 KB
testcase_03 AC 82 ms
26,624 KB
testcase_04 AC 59 ms
22,528 KB
testcase_05 AC 180 ms
41,472 KB
testcase_06 AC 162 ms
42,368 KB
testcase_07 AC 101 ms
30,208 KB
testcase_08 AC 46 ms
21,248 KB
testcase_09 AC 77 ms
25,728 KB
testcase_10 AC 117 ms
32,000 KB
testcase_11 AC 109 ms
31,360 KB
testcase_12 AC 133 ms
34,176 KB
testcase_13 AC 51 ms
21,888 KB
testcase_14 AC 40 ms
20,736 KB
testcase_15 AC 167 ms
42,752 KB
testcase_16 AC 184 ms
42,112 KB
testcase_17 AC 148 ms
41,088 KB
testcase_18 AC 67 ms
24,960 KB
testcase_19 AC 157 ms
42,368 KB
testcase_20 AC 188 ms
42,240 KB
testcase_21 AC 185 ms
42,496 KB
testcase_22 AC 187 ms
42,496 KB
testcase_23 AC 190 ms
42,368 KB
testcase_24 AC 195 ms
42,624 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var d = new Dictionary<long, int>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        for (int i = 0; i < n; i++)
            if (d.ContainsKey(a[i])) d[a[i]]++;
            else d[a[i]] = 1;
        var ans = getAns(d, n);
        Console.WriteLine(ans);
    }
    public static long getAns (Dictionary<long,int> d , int n)
    {
        var count = 0;  var med = 0L;
        foreach (var x in d.OrderBy(y =>y.Key))
        {
            count += x.Value;
            if (count >= (n + 1) / 2) { med = x.Key; break; }
        }
        var ans = 0L;
        foreach (var x in d.OrderBy(y => y.Key))
            ans += x.Value * Abs(med - x.Key);
        return ans;
    }
}
0