結果

問題 No.185 和風
ユーザー koukonkokoukonko
提出日時 2015-12-14 15:15:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 78 ms / 1,000 ms
コード長 847 bytes
コンパイル時間 2,027 ms
コンパイル使用メモリ 72,304 KB
実行使用メモリ 51,684 KB
最終ジャッジ日時 2023-10-13 16:32:56
合計ジャッジ時間 2,951 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
49,452 KB
testcase_01 AC 78 ms
51,316 KB
testcase_02 AC 45 ms
49,300 KB
testcase_03 AC 45 ms
49,284 KB
testcase_04 AC 44 ms
49,260 KB
testcase_05 AC 44 ms
49,200 KB
testcase_06 AC 67 ms
51,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		try {

			int N = Integer.parseInt(read.readLine());
			int num;
			String[] box = read.readLine().split(" ");

			int x, y;
			x = Integer.parseInt(box[0]);
			y = Integer.parseInt(box[1]);

			num = y - x;
			if (num <= 0) {
				System.out.println(-1);
				return;
			}
			int i;
			for (i = 1; i < N; ++i) {
				box = read.readLine().split(" ");

				x = Integer.parseInt(box[0]);
				y = Integer.parseInt(box[1]);

				if (num != (y - x)) {
					break;
				}
			}

			if (i < N) {
				System.out.println(-1);
			} else {
				System.out.println(num);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
0