結果
| 問題 |
No.609 Noelちゃんと星々
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2018-10-08 19:29:54 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 193 ms / 2,000 ms |
| コード長 | 960 bytes |
| コンパイル時間 | 2,517 ms |
| コンパイル使用メモリ | 113,172 KB |
| 実行使用メモリ | 42,624 KB |
| 最終ジャッジ日時 | 2024-10-12 15:25:57 |
| 合計ジャッジ時間 | 6,906 ms |
|
ジャッジサーバーID (参考情報) |
judge / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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;
}
}
bluemegane