結果
| 問題 |
No.185 和風
|
| コンテスト | |
| ユーザー |
Eclair1015
|
| 提出日時 | 2018-08-09 00:38:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 542 bytes |
| コンパイル時間 | 514 ms |
| コンパイル使用メモリ | 61,396 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-23 04:16:41 |
| 合計ジャッジ時間 | 1,001 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:27: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
29 | if (flag) cout << ans << endl;
| ^~~
ソースコード
#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;
}
if (i == 0 && ans < 0) {
flag = false;
break;
}
check = ans;
}
if (n == 1)flag = false;
if (flag) cout << ans << endl;
else cout << -1 << endl;
return 0;
}
Eclair1015