結果
問題 | No.1120 Strange Teacher |
ユーザー |
|
提出日時 | 2020-07-22 21:43:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 1,000 ms |
コード長 | 975 bytes |
コンパイル時間 | 1,903 ms |
コンパイル使用メモリ | 170,496 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-22 14:58:11 |
合計ジャッジ時間 | 2,713 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr char newl = '\n'; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector<ll> a(n); ll suma = 0; for (int i = 0; i < n; i++) { cin >> a[i]; suma += a[i]; } vector<ll> b(n); ll sumb = 0; for (int i = 0; i < n; i++) { cin >> b[i]; sumb += b[i]; } ll diff = suma - sumb; if (n == 2) { cout << (diff == 0 ? abs(a[0] - b[0]) : -1) << newl; return 0; } if (diff < 0 || diff % (n - 2) != 0) { cout << -1 << newl; return 0; } ll cnt = diff / (n - 2); for (int i = 0; i < n; i++) { a[i] -= cnt; } for (int i = 0; i < n; i++) { ll tmp = b[i] - a[i]; if (tmp < 0 || tmp % 2 != 0) { cout << -1 << newl; return 0; } } cout << cnt << newl; return 0; }