結果

問題 No.185 和風
ユーザー Grenache
提出日時 2015-11-03 11:59:46
言語 Java
(openjdk 23)
結果
AC  
実行時間 206 ms / 1,000 ms
コード長 672 bytes
コンパイル時間 3,424 ms
コンパイル使用メモリ 74,568 KB
実行使用メモリ 56,824 KB
最終ジャッジ日時 2024-09-13 12:04:00
合計ジャッジ時間 5,445 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder185 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int prev = 0;
        boolean flag = true;
        for (int i = 0; i < n; i++) {
        	int x = sc.nextInt();
        	int y = sc.nextInt();
        	if (i > 0) {
        		if (y - x != prev) {
        			flag = false;
        			break;
        		}
        	} else {
        		prev = y - x;
        	}
        }

        if (flag && prev > 0) {
        	System.out.println(prev);
        } else {
        	System.out.println("-1");
        }
        
        sc.close();
    }
}
0