結果

問題 No.185 和風
ユーザー cande398cande398
提出日時 2018-03-07 01:30:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 345 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 55,348 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 04:50:08
合計ジャッジ時間 1,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

int main(void)
{
	int N, X, Y, ans;
	bool error = false;
	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> X >> Y;
		if(i == 0) ans = Y - X;
		if(Y - X != ans) {
			error = true;
		}
		else if(ans < 1) {
			error = true;
		}
	}
	if(error) {
		cout << "-1" << endl;
	}
	else {
		cout << ans << endl;
	}
}
0