結果
問題 | No.1120 Strange Teacher |
ユーザー |
|
提出日時 | 2020-07-23 02:41:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 24 ms / 1,000 ms |
コード長 | 898 bytes |
コンパイル時間 | 1,968 ms |
コンパイル使用メモリ | 194,576 KB |
最終ジャッジ日時 | 2025-01-12 04:06:11 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;signed main() {ios::sync_with_stdio(false); cin.tie(0);int n;cin >> n;vector<long long> a(n), b(n);long long sum_a = 0, sum_b = 0;for (auto& x : a) {cin >> x;sum_a += x;}for (auto& x : b) {cin >> x;sum_b += x;}if (n >= 3) {if (sum_a < sum_b || (sum_a - sum_b) % (n - 2) != 0) {cout << -1 << endl;return 0;}long long opr = (sum_a - sum_b) / (n - 2);for (auto& x : a) {x -= opr;}long long cnt = 0;for (int i = 0; i < n; i++) {if (a[i] > b[i] || (b[i] - a[i]) % 2 != 0) {cout << -1 << endl;return 0;}cnt += (b[i] - a[i]) / 2;}cout << (opr == cnt ? opr : -1) << endl;} else {cout << ((a[0] - b[0]) == (b[1] - a[1]) ? abs(a[0] - b[0]) : -1) << endl;}return 0;}