結果

問題 No.1120 Strange Teacher
ユーザー rogi52rogi52
提出日時 2022-10-10 06:05:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,060 bytes
コンパイル時間 2,130 ms
コンパイル使用メモリ 200,816 KB
実行使用メモリ 4,828 KB
最終ジャッジ日時 2023-09-06 07:20:19
合計ジャッジ時間 4,847 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 22 ms
4,632 KB
testcase_05 AC 22 ms
4,568 KB
testcase_06 AC 22 ms
4,544 KB
testcase_07 AC 22 ms
4,548 KB
testcase_08 AC 22 ms
4,544 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 22 ms
4,548 KB
testcase_11 AC 22 ms
4,616 KB
testcase_12 AC 22 ms
4,560 KB
testcase_13 AC 22 ms
4,620 KB
testcase_14 AC 21 ms
4,568 KB
testcase_15 AC 22 ms
4,628 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 23 ms
4,688 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 20 ms
4,576 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll N; cin >> N;
    vector<ll> A(N), B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];

    if(N == 2) {
        if(A[0] - B[0] == -(A[1] - B[1])) {
            cout << abs(A[0] - B[0]) << endl;
        } else {
            cout << -1 << endl;
        }
        return 0;
    }

    // N-2ずつ減る
    ll sumA = accumulate(A.begin(), A.end(), 0LL);
    ll sumB = accumulate(B.begin(), B.end(), 0LL);
    if((sumB - sumA) % (N - 2) != 0 || sumB > sumA) { cout << -1 << endl; return 0; }

    ll K = (sumA - sumB) / (N - 2);
    ll cnt = 0;
    rep(i,N) {
        // x + y = K
        // x - y = B - A

        // 2x = K + B - A
        // 2y = K - B + A
        if((K + B[i] - A[i]) % 2 != 0){ cout << -1 << endl; return 0; }
        cnt  += (K + B[i] - A[i]) / 2;
    }

    if(cnt == K) {
        cout << cnt << endl;
    } else {
        cout << -1 << endl;
    }
}
0