結果

問題 No.185 和風
コンテスト
ユーザー t8m8⛄️
提出日時 2015-04-19 23:23:36
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 115 ms / 1,000 ms
コード長 972 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,901 ms
コンパイル使用メモリ 83,776 KB
実行使用メモリ 46,556 KB
最終ジャッジ日時 2026-03-26 01:23:30
合計ジャッジ時間 4,028 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No0185 {
    
    static final Scanner in = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        int n = in.nextInt();
        int res = 0;
        for (int i=0; i<n; i++) {
            int x = in.nextInt();
            int y = in.nextInt();
            if (res == -1) continue;
            if (i == 0)
                res = y - x;
            else if (res != y - x) res = -1;
        }
        out.println(res <= 0 ? "-1" : res);
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        in.close();
        out.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}
}
0