結果
| 問題 |
No.2548 Problem Selection
|
| コンテスト | |
| ユーザー |
heno239
|
| 提出日時 | 2024-02-06 15:52:03 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 90 ms / 2,000 ms |
| コード長 | 1,345 bytes |
| コンパイル時間 | 9,493 ms |
| コンパイル使用メモリ | 165,184 KB |
| 実行使用メモリ | 185,552 KB |
| 最終ジャッジ日時 | 2024-09-28 12:05:13 |
| 合計ジャッジ時間 | 11,194 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (100 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System.Collections;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
internal class Program
{
private const long mod = 998244353;
private const long mod17 = 1000000007;
private const long INF = mod17 * mod17;
public static void Main(string[] args)
{
var line = getar();
int n = line[0], m = line[1];
var a = getar();
Array.Sort(a);
List<long> rd = mkar(n, (long)0);
for (int i = 0; i + 1 < n; i++)
{
long dif = a[i + 1] - a[i];
rd[i + 1] = rd[i] + dif * dif;
}
long ans = INF;
for (int i = 0; i < n - (m - 1); i++)
{
long val = rd[i + m - 1] - rd[i];
ans = Math.Min(ans, val);
}
Console.WriteLine(ans);
}
public class lower_bound<T> : IComparer<T> where T : IComparable<T>
{
public int Compare(T x, T y)
{
return 0 <= x.CompareTo(y) ? 1 : -1;
}
}
public static List<T> mkar<T>(int n, T val)
{
List<T> res = new List<T>(n);
for(int i=0;i<n;i++)res.Add(val);
return res;
}
public static int[] getar()
{
var res = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
return res;
}
}
heno239