結果

問題 No.185 和風
ユーザー GrenacheGrenache
提出日時 2015-11-03 11:59:46
言語 Java19
(openjdk 21)
結果
AC  
実行時間 195 ms / 1,000 ms
コード長 672 bytes
コンパイル時間 3,045 ms
コンパイル使用メモリ 71,932 KB
実行使用メモリ 58,752 KB
最終ジャッジ日時 2023-10-11 13:18:39
合計ジャッジ時間 5,043 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 179 ms
55,956 KB
testcase_01 AC 195 ms
58,752 KB
testcase_02 AC 124 ms
55,664 KB
testcase_03 AC 127 ms
55,608 KB
testcase_04 AC 193 ms
56,188 KB
testcase_05 AC 143 ms
56,248 KB
testcase_06 AC 192 ms
58,564 KB
権限があれば一括ダウンロードができます

ソースコード

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