結果

問題 No.1120 Strange Teacher
ユーザー risujiroh
提出日時 2020-07-22 21:29:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 907 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 194,540 KB
最終ジャッジ日時 2025-01-12 02:10:50
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using ll = long long;
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  for (auto&& e : a) cin >> e;
  for (auto&& e : b) cin >> e;
  auto d = accumulate(begin(a), end(a), 0LL) - accumulate(begin(b), end(b), 0LL);
  if (n == 2) {
    if (d) {
      cout << "-1\n";
    } else {
      cout << abs(a[0] - b[0]) << '\n';
    }
    exit(0);
  }
  if (d < 0 or d % (n - 2)) {
    cout << "-1\n";
    exit(0);
  }
  ll num = d / (n - 2), sum = 0;
  for (int i = 0; i < n; ++i) {
    ll delta = b[i] - a[i];
    if ((num + delta) & 1) {
      cout << "-1\n";
      exit(0);
    }
    ll x = (num + delta) / 2;
    if (x < 0 or x > num) {
      cout << "-1\n";
      exit(0);
    }
    sum += x;
  }
  cout << num << '\n';
  DEBUG(sum);
}
0