結果

問題 No.185 和風
ユーザー kiyunetsubamnakiyunetsubamna
提出日時 2015-05-19 11:27:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 442 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 57,220 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 10:12:31
合計ジャッジ時間 1,083 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:35:11: warning: ‘a’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   cout << a << endl;
           ^

ソースコード

diff #

#include<iostream>
#include <math.h>
#include <string>
using namespace std;

int main(){
	int n;
	int x;
	int y;
	int a;
	int flag;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> x;
		cin >> y;
		if (i == 0){
			a = y - x;
			if (a <= 0){
				flag = 1;
				break;
			}
		}
		else if (a != y - x){
			flag = 1;
			break;
		}
		else{
			flag = 0;
		}
	}
	if (flag == 1){
		cout << "-1" << endl;
	}
	else{
		cout << a << endl;
	}
	return 0;
}
0