結果
| 問題 | No.1120 Strange Teacher |
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2020-07-22 21:38:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 1,000 ms |
| コード長 | 1,013 bytes |
| 記録 | |
| コンパイル時間 | 937 ms |
| コンパイル使用メモリ | 92,644 KB |
| 最終ジャッジ日時 | 2025-01-12 02:22:34 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n), b(n);
ll s = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
s -= b[i];
}
if (n == 2) {
if (s == 0) {
cout << abs(b[0] - a[0]) << endl;
} else {
cout << -1 << endl;
}
exit(0);
}
if (s % (n - 2) != 0 || s < 0) {
cout << -1 << endl;
exit(0);
}
ll r = s / (n - 2);
for (int i = 0; i < n; i++) {
ll t = r + b[i] - a[i];
if (!(t >= 0 && t % 2 == 0)) r = -1;
}
cout << r << endl;
//1回操作をする毎に全体の和はn-2だけ減る 可能であれば操作回数がわかる
return 0;
}
merom686