結果
| 問題 | No.1120 Strange Teacher |
| コンテスト | |
| ユーザー |
cider
|
| 提出日時 | 2020-07-22 22:04:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 1,000 ms |
| コード長 | 677 bytes |
| コンパイル時間 | 2,111 ms |
| コンパイル使用メモリ | 195,604 KB |
| 最終ジャッジ日時 | 2025-01-12 02:46:42 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
vector<ll> a(n);
for (ll i = 0; i < n; ++i)cin >> a[i];
for (ll i = 0; i < n; ++i) {
ll b;
cin >> b;
a[i] -= b;
}
if (n == 2) {
if (a[0] + a[1] == 0)cout << abs(a[0]) << endl;
else cout << -1 << endl;
return 0;
}
ll sum = accumulate(a.begin(), a.end(), 0ll);
if (sum % (n - 2) != 0 || sum < 0) {
cout << -1 << endl;
return 0;
}
sum /= n - 2;
for (ll i = 0; i < n; ++i) {
if ((sum + a[i]) % 2 != 0) {
cout << -1 << endl;
return 0;
}
if (a[i] - sum > 0 || a[i] + sum < 0) {
cout << -1 << endl;
return 0;
}
}
cout << sum << endl;
}
cider