結果
問題 |
No.1120 Strange Teacher
|
ユーザー |
![]() |
提出日時 | 2020-07-09 16:48:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 70 ms / 1,000 ms |
コード長 | 748 bytes |
コンパイル時間 | 601 ms |
コンパイル使用メモリ | 68,736 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 20:53:59 |
合計ジャッジ時間 | 2,739 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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); } cout << S << endl; return 0; }