結果
問題 |
No.1120 Strange Teacher
|
ユーザー |
![]() |
提出日時 | 2020-07-22 21:29:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 978 bytes |
コンパイル時間 | 1,562 ms |
コンパイル使用メモリ | 160,596 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-22 13:44:44 |
合計ジャッジ時間 | 3,168 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1000000007; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); vector<int> B(N); int res = 0; int sumA = 0; int sumB = 0; for (int i = 0; i < N; i++) { cin >> A[i]; sumA += A[i]; } for (int i = 0; i < N; i++) { cin >> B[i]; sumB += B[i]; } if (N == 2) { if (sumA != sumB) { cout << -1 << endl; } else { cout << abs(A[0] - B[0]) << endl; } } else { bool ok = true; if (sumA < sumB) { ok = false; } else { int k = sumA - sumB; if (k % (N - 2) != 0) { ok = false; } else { int tot = k / (N - 2); int c = 0; for (int i = 0; i < N; i++) { int t = (B[i] - A[i] + tot); if (t % 2 != 0) { ok = false; } c += t / 2; } if (c != tot) { ok = false; } if (ok) { cout << tot << endl; } } } if (!ok) { cout << -1 << endl; } } }