結果
問題 | No.1120 Strange Teacher |
ユーザー |
![]() |
提出日時 | 2020-07-09 16:21:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 70 ms / 1,000 ms |
コード長 | 790 bytes |
コンパイル時間 | 597 ms |
コンパイル使用メモリ | 68,864 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 20:52:14 |
合計ジャッジ時間 | 2,835 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <iostream>#include <cmath>using namespace std;long long N, A[1 << 18], B[1 << 18];int main() {cin >> N;for (int i = 1; i <= N; i++) cin >> A[i];for (int i = 1; i <= N; i++) cin >> B[i];if (N == 2LL) {long long ans = abs(A[1] - B[1]);if (A[1] + A[2] != B[1] + B[2]) ans = -1;cout << ans << endl;return 0;}long long S = 0;for (int i = 1; i <= N; i++) S += A[i];for (int i = 1; i <= N; i++) S -= B[i];if (S < 0 || S % (N - 2LL) != 0) { cout << "-1" << endl; return 0; }S /= (N - 2LL);long long cnt = 0;for (int i = 1; i <= N; i++) {long long eval = B[i] - (A[i] - S);if (eval % 2 == 1 || eval < 0) { cout << "-1" << endl; return 0; }cnt += (eval / 2LL);}if (cnt != S) cout << "-1" << endl;else cout << S << endl;return 0;}