結果

問題 No.135 とりあえず1次元の問題
コンテスト
ユーザー 大谷祐翔
提出日時 2025-11-11 11:34:33
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 92 ms / 5,000 ms
コード長 1,153 bytes
コンパイル時間 7,896 ms
コンパイル使用メモリ 171,040 KB
実行使用メモリ 43,468 KB
最終ジャッジ日時 2025-11-11 11:35:08
合計ジャッジ時間 10,293 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (101 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

class Program
{
    static void Main(string[] args)
    {
        string inputCount = Console.ReadLine()!;
        string[] inputNum = Console.ReadLine()!.Split(' ');
        List<int> numList = new List<int>();
        int ans = 0;
        int count = 0;

        if (inputCount == "1")
        {
            Console.WriteLine(0);
            return;
        }

        for (int i = 0; i < inputNum.Length; i++)
        {
            numList.Add(int.Parse(inputNum[i]));
        }

        numList.Sort();
        for (int i = 1; i < numList.Count; i++)
        {
            int firstPoint = numList[i - 1];
            int secondPoint = numList[i];

            if (secondPoint - firstPoint != 0)
            {
                if (count == 0)
                {
                    ans = secondPoint - firstPoint;
                    count++;
                }
                else if (ans > secondPoint - firstPoint && count == 1)
                {
                    ans = secondPoint - firstPoint;
                }
            }
        }

        if (ans <= -1)
        {
            ans *= -1;
        }

        Console.WriteLine(ans);
    }
}
0