結果

問題 No.1120 Strange Teacher
ユーザー MisterMister
提出日時 2020-08-02 14:20:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 1,000 ms
コード長 1,012 bytes
コンパイル時間 994 ms
コンパイル使用メモリ 74,824 KB
実行使用メモリ 5,136 KB
最終ジャッジ日時 2023-09-25 16:31:24
合計ジャッジ時間 5,681 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 22 ms
4,632 KB
testcase_05 AC 22 ms
4,568 KB
testcase_06 AC 21 ms
4,572 KB
testcase_07 AC 22 ms
4,620 KB
testcase_08 AC 22 ms
4,620 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 22 ms
5,136 KB
testcase_11 AC 22 ms
4,952 KB
testcase_12 AC 23 ms
4,980 KB
testcase_13 AC 22 ms
4,988 KB
testcase_14 AC 22 ms
5,132 KB
testcase_15 AC 22 ms
5,020 KB
testcase_16 AC 22 ms
4,952 KB
testcase_17 AC 22 ms
4,984 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 24 ms
4,708 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 19 ms
4,580 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <numeric>
#include <vector>

using lint = long long;

void fail() {
    std::cout << -1 << "\n";
    std::exit(0);
}

void solve() {
    int n;
    std::cin >> n;

    std::vector<lint> xs(n), ys(n);
    for (auto& x : xs) std::cin >> x;
    for (auto& y : ys) std::cin >> y;

    auto xsum = std::accumulate(xs.begin(), xs.end(), 0LL);
    auto ysum = std::accumulate(ys.begin(), ys.end(), 0LL);

    if (n == 2) {
        if (xsum != ysum) fail();
        std::cout << std::abs(xs[0] - ys[0]) << "\n";
        return;
    }

    if (xsum < ysum || (xsum - ysum) % (n - 2) != 0) fail();

    auto ope = (xsum - ysum) / (n - 2);
    lint need = 0;
    for (int i = 0; i < n; ++i) {
        xs[i] -= ope;
        if (xs[i] > ys[i] || (ys[i] - xs[i]) % 2 != 0) fail();
        need += (ys[i] - xs[i]) / 2;
    }

    if (need != ope) fail();

    std::cout << ope << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0