結果

問題 No.185 和風
コンテスト
ユーザー Eclair1015
提出日時 2018-08-09 00:36:55
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 484 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 470 ms
コンパイル使用メモリ 78,616 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2026-04-11 09:30:38
合計ジャッジ時間 1,232 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:25:27: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   25 |         if (flag) cout << ans << endl;
      |                           ^~~
main.cpp:14:13: note: 'ans' was declared here
   14 |         int ans,check;
      |             ^~~

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <vector>
#include<string>

using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

	int ans,check;
	bool flag = true;
	for (int i = 0; i < n; i++) {
		ans = b[i] - a[i];
		if (i != 0 && ans != check) {
			flag = false;
			break;
		}
		check = ans;
	}
	if (n == 1)flag = false;
	if (flag) cout << ans << endl;
	else cout << -1 << endl;
	return 0;
}

0