結果

問題 No.275 中央値を求めよ
ユーザー cccccc
提出日時 2022-07-15 14:38:21
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 61 ms / 1,000 ms
コード長 974 bytes
コンパイル時間 14,602 ms
コンパイル使用メモリ 146,992 KB
実行使用メモリ 164,856 KB
最終ジャッジ日時 2023-09-09 16:19:28
合計ジャッジ時間 12,198 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
28,644 KB
testcase_01 AC 54 ms
30,844 KB
testcase_02 AC 56 ms
29,024 KB
testcase_03 AC 53 ms
28,880 KB
testcase_04 AC 54 ms
30,832 KB
testcase_05 AC 54 ms
28,852 KB
testcase_06 AC 55 ms
28,772 KB
testcase_07 AC 57 ms
29,068 KB
testcase_08 AC 56 ms
29,176 KB
testcase_09 AC 56 ms
29,172 KB
testcase_10 AC 56 ms
29,264 KB
testcase_11 AC 52 ms
28,676 KB
testcase_12 AC 52 ms
28,864 KB
testcase_13 AC 52 ms
28,960 KB
testcase_14 AC 53 ms
28,916 KB
testcase_15 AC 58 ms
28,972 KB
testcase_16 AC 56 ms
29,236 KB
testcase_17 AC 56 ms
31,144 KB
testcase_18 AC 56 ms
29,036 KB
testcase_19 AC 56 ms
29,132 KB
testcase_20 AC 56 ms
29,084 KB
testcase_21 AC 56 ms
29,116 KB
testcase_22 AC 58 ms
28,908 KB
testcase_23 AC 56 ms
29,148 KB
testcase_24 AC 57 ms
28,872 KB
testcase_25 AC 57 ms
31,256 KB
testcase_26 AC 55 ms
29,208 KB
testcase_27 AC 56 ms
29,120 KB
testcase_28 AC 54 ms
29,108 KB
testcase_29 AC 56 ms
29,012 KB
testcase_30 AC 54 ms
28,916 KB
testcase_31 AC 55 ms
29,108 KB
testcase_32 AC 56 ms
29,180 KB
testcase_33 AC 56 ms
29,028 KB
testcase_34 AC 57 ms
29,092 KB
testcase_35 AC 56 ms
29,412 KB
testcase_36 AC 56 ms
29,352 KB
testcase_37 AC 56 ms
29,008 KB
testcase_38 AC 56 ms
29,052 KB
testcase_39 AC 61 ms
30,872 KB
testcase_40 AC 59 ms
164,856 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  Determining projects to restore...
  Restored /home/judge/data/code/main.csproj (in 162 ms).
.NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f
Copyright (C) Microsoft Corporation.All rights reserved.

  プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください
  main -> /home/judge/data/code/bin/Release/net6.0/main.dll
  main -> /home/judge/data/code/bin/Release/net6.0/publish/

ソースコード

diff #

using System;
using System.Linq;
class Program
{
    static void Main()
    {
        var cnt = Console.ReadLine();
        var lin = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Array.Sort(lin);

        // 配列数に応じて偶数時・奇数時の処理
        if (lin.Length % 2 == 0)
            Even(lin);
        else
            Odd(lin);

        // 奇数の場合の処理
        int Odd(int[] arg)
        {
            var charg = arg[arg.Length / 2];
            double ans = Math.Ceiling((double)charg);
            Console.WriteLine(ans);
            return 1;
        }
        // 偶数の場合の処理
        int Even(int[] arg)
        {
            // double型で中央値に近似する左右のインデックスを取得し計算
            var charg = (double)(arg[arg.Length / 2] + arg[(arg.Length / 2) - 1] ) / 2;
            var ans = charg;
            Console.WriteLine(ans);
            return 1;
        }
    }
}
0