結果

問題 No.1120 Strange Teacher
ユーザー KoDKoD
提出日時 2020-07-22 21:36:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 1,000 ms
コード長 2,425 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 77,516 KB
実行使用メモリ 4,748 KB
最終ジャッジ日時 2023-09-04 16:08:15
合計ジャッジ時間 5,141 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 7 ms
4,384 KB
testcase_04 AC 58 ms
4,576 KB
testcase_05 AC 58 ms
4,596 KB
testcase_06 AC 58 ms
4,704 KB
testcase_07 AC 58 ms
4,556 KB
testcase_08 AC 58 ms
4,548 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 59 ms
4,588 KB
testcase_11 AC 58 ms
4,576 KB
testcase_12 AC 58 ms
4,720 KB
testcase_13 AC 58 ms
4,548 KB
testcase_14 AC 58 ms
4,584 KB
testcase_15 AC 57 ms
4,632 KB
testcase_16 AC 58 ms
4,696 KB
testcase_17 AC 58 ms
4,636 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 64 ms
4,604 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 50 ms
4,748 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,388 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"

/**
 * @title Template
 */

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { ++i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr range(itr l_, itr r_) noexcept : l(l_), r(std::max(l_, r_)) { }
  constexpr iterator begin() const noexcept { return l; }
  constexpr iterator end() const noexcept { return r; }
};

struct revrange {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { --i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr revrange(itr l_, itr r_) noexcept : l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr iterator begin() const noexcept { return r; }
  constexpr iterator end() const noexcept { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  i32 N;
  std::cin >> N;
  std::vector<i64> A(N), B(N);
  for (auto &x: A) {
    std::cin >> x;
  }
  for (auto &x: B) {
    std::cin >> x;
  }
  if (N == 2) {
    if (A[0] + A[1] == B[0] + B[1]) {
      std::cout << std::max(B[0] - A[0], i64(0)) + std::max(B[1] - A[1], i64(0)) << '\n';
    }
    else {
      std::cout << "-1\n";
    }
    return 0;
  }
  i64 sum = 0;
  for (auto i: range(0, N)) {
    sum += B[i] - A[i];
  }
  if (sum > 0 || sum % (N - 2) != 0) {
    std::cout << "-1\n";
    return 0;
  }
  sum /= (2 - N);
  for (auto i: range(0, N)) {
    i64 tmp = B[i] - A[i] + sum;
    if (tmp % 2 != 0 || tmp < 0) {
      std::cout << "-1\n";
      return 0;
    }
  }
  std::cout << sum << '\n';
  return 0;
}
0