結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N),B(N);
    ll asum = 0,bsum = 0;
    for(auto& x:A){
        cin >> x;
        asum += x;
    }
    for(auto& x:B){
        cin >> x;
        bsum += x;
    }
    if(N==2){
        assert(false);
        ll d0 = A[0]-B[0],d1 = A[1]-B[1];
        cout << ((d0+d1==0)? abs(d0):-1) << "\n";
        return 0;
    }
    if((asum-bsum)%(N-2)!=0){
        cout << -1 << "\n";
        return 0;
    }
    ll ans = (asum-bsum)/(N-2);
    ll cnt = 0;
    for(int i=0;i<N;i++){
        ll d = B[i]-A[i];
        if((ans+d)%2){
            cout << -1 << "\n";
            return 0;
        }
        cnt += (ans+d)/2;
    }
    cerr << ans << " " << cnt << "\n";
    cout << (ans==cnt? ans:-1) << "\n";
}
0