結果
| 問題 |
No.1120 Strange Teacher
|
| コンテスト | |
| ユーザー |
onsen_manjuuu
|
| 提出日時 | 2020-07-23 00:22:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 1,000 ms |
| コード長 | 872 bytes |
| コンパイル時間 | 1,784 ms |
| コンパイル使用メモリ | 169,016 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-23 02:51:51 |
| 合計ジャッジ時間 | 3,424 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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), b(n);
for(ll i = 0; i < n; i++)cin >> a[i];
for(ll i = 0; i < n; i++)cin >> b[i];
ll sum = 0, k = 0, use = 0;
for(ll i = 0; i < n; i++) sum += (a[i] - b[i]);
if(n == 2 && sum) {
cout << -1 << endl;
return 0;
}else if(n == 2 && sum == 0) {
cout << abs(a[0] - b[0]) << endl;
return 0;
}
if(sum % (n - 2)) {
cout << -1 << endl; return 0;
}
k = sum / (n - 2);
for(ll i = 0; i < n; i++) {
if((b[i] - a[i] + k) % 2 || (b[i] - a[i] + k) < 0) {
cout << -1 << endl;
return 0;
}
use += (b[i] - a[i] + k) / 2;
}
if(use != k) {
cout << -1 << endl;
return 0;
}
cout << k << endl;
}
onsen_manjuuu