結果

問題 No.185 和風
コンテスト
ユーザー りな
提出日時 2025-11-10 16:05:15
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 1,269 bytes
コンパイル時間 7,177 ms
コンパイル使用メモリ 171,152 KB
実行使用メモリ 189,072 KB
最終ジャッジ日時 2025-11-10 16:05:26
合計ジャッジ時間 8,401 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 2 MLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (104 ミリ秒)。
/home/judge/data/code/Main.cs(11,15): warning CS8632: '#nullable' 注釈コンテキスト内のコードでのみ、Null 許容参照型の注釈を使用する必要があります。 [/home/judge/data/code/main.csproj]
/home/judge/data/code/Main.cs(17,19): warning CS8632: '#nullable' 注釈コンテキスト内のコードでのみ、Null 許容参照型の注釈を使用する必要があります。 [/home/judge/data/code/main.csproj]
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.IO;

class Program
{
    static void Main()
    {
        using var sr = new StreamReader(Console.OpenStandardInput(), bufferSize: 1 << 16);
        using var sw = new StreamWriter(Console.OpenStandardOutput());
        // 1行目
        string? s = sr.ReadLine();
        int count = int.Parse(s!);

        int ansSave = int.MinValue; // 未設定を表す
        for (int i = 0; i < count; i++)
        {
            string? line = sr.ReadLine();
            if (line is null) { sw.WriteLine(-1); return; }

            int sp = line.IndexOf(' ');
            if (sp < 0) { sw.WriteLine(-1); return; }

            ReadOnlySpan<char> a = line.AsSpan(0, sp);
            ReadOnlySpan<char> b = line.AsSpan(sp + 1);

            if (!int.TryParse(a, out int left) || !int.TryParse(b, out int right))
            {
                sw.WriteLine(-1);
                return;
            }

            int diff = right - left;
            if (i == 0)
            {
                ansSave = diff;
            }
            else if (ansSave != diff)
            {
                sw.WriteLine(-1);
                return; // 早期終了
            }
        }

        if (ansSave != int.MinValue)
            sw.WriteLine(ansSave);
    }
}
0