結果
問題 | No.1120 Strange Teacher |
ユーザー |
![]() |
提出日時 | 2022-11-11 18:41:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 71 ms / 1,000 ms |
コード長 | 903 bytes |
コンパイル時間 | 1,574 ms |
コンパイル使用メモリ | 169,388 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-13 13:24:47 |
合計ジャッジ時間 | 4,702 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int64_t n; cin >> n; vector<int64_t> a(n); vector<int64_t> b(n); int64_t as = 0; int64_t bs = 0; for(int64_t i = 0; i < n; i++) { cin >> a[i]; as += a[i]; } for(int64_t i = 0; i < n; i++) { cin >> b[i]; bs += b[i]; } if(as - bs < 0) { cout << -1 << endl; return 0; } if(n == 2) { if(as != bs) cout << -1 << endl; else cout << abs(a[0] - b[0]) << endl; return 0; } if((as - bs) % (n - 2) != 0) { cout << -1 << endl; return 0; } int64_t k = (as - bs) / (n - 2); for(int64_t i = 0; i < n; i++) a[i] -= k; int64_t cnt = 0; for(int64_t i = 0; i < n; i++) { if(a[i] > b[i]) { cout << -1 << endl; return 0; } if((b[i] - a[i]) % 2 != 0) { cout << -1 << endl; return 0; } cnt += (b[i] - a[i]) / 2; } if(k == cnt) cout << k << endl; else cout << -1 << endl; return 0; }