結果

問題 No.2548 Problem Selection
ユーザー bluemeganebluemegane
提出日時 2023-11-25 20:08:21
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 19,835 ms
コンパイル使用メモリ 158,788 KB
実行使用メモリ 178,640 KB
最終ジャッジ日時 2023-11-25 20:08:48
合計ジャッジ時間 17,850 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 237 ms
44,108 KB
testcase_01 AC 114 ms
34,724 KB
testcase_02 AC 255 ms
47,688 KB
testcase_03 AC 88 ms
33,060 KB
testcase_04 AC 177 ms
38,692 KB
testcase_05 AC 254 ms
47,476 KB
testcase_06 AC 90 ms
33,316 KB
testcase_07 AC 235 ms
43,712 KB
testcase_08 AC 224 ms
45,128 KB
testcase_09 AC 234 ms
45,832 KB
testcase_10 AC 262 ms
48,160 KB
testcase_11 AC 275 ms
48,160 KB
testcase_12 AC 265 ms
48,160 KB
testcase_13 AC 63 ms
31,396 KB
testcase_14 AC 59 ms
31,012 KB
testcase_15 AC 62 ms
31,396 KB
testcase_16 AC 63 ms
31,396 KB
testcase_17 AC 63 ms
31,396 KB
testcase_18 AC 63 ms
31,396 KB
testcase_19 AC 62 ms
31,396 KB
testcase_20 AC 59 ms
31,012 KB
testcase_21 AC 62 ms
31,396 KB
testcase_22 AC 63 ms
31,396 KB
testcase_23 AC 62 ms
31,396 KB
testcase_24 AC 71 ms
31,396 KB
testcase_25 AC 63 ms
31,396 KB
testcase_26 AC 62 ms
178,640 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (105 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        getAns(n, k, a);
    }
    static void getAns(int n, int k, long[] a)
    {
        Array.Sort(a);
        var b = new long[n - 1];
        for (int i = 0; i < n - 1; i++)
        {
            var t = a[i + 1] - a[i];
            b[i] = t * t;
        }
        var s = 0L;
        for (int i = 0; i < k - 1; i++) s += b[i];
        var c = new long[n];
        c[0] = 0;
        for (int i = 1; i < n; i++) c[i] = c[i - 1] + b[i - 1];
        var ans = long.MaxValue;
        for (int i = k - 1; i < n; i++) ans = Min(ans, c[i] - c[i - k + 1]);
        Console.WriteLine(ans);
    }
}
0