結果

問題 No.1120 Strange Teacher
ユーザー yuji9511yuji9511
提出日時 2020-07-22 21:35:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 1,489 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 199,916 KB
実行使用メモリ 5,176 KB
最終ジャッジ日時 2023-09-04 15:53:53
合計ジャッジ時間 4,079 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 22 ms
4,924 KB
testcase_05 AC 22 ms
5,020 KB
testcase_06 AC 22 ms
4,932 KB
testcase_07 AC 22 ms
4,828 KB
testcase_08 AC 22 ms
5,176 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 22 ms
4,860 KB
testcase_11 AC 22 ms
4,936 KB
testcase_12 AC 22 ms
4,912 KB
testcase_13 AC 22 ms
4,872 KB
testcase_14 AC 22 ms
4,928 KB
testcase_15 AC 22 ms
5,172 KB
testcase_16 AC 22 ms
4,832 KB
testcase_17 AC 22 ms
5,000 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 23 ms
4,996 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 20 ms
4,924 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N;
    cin >> N;
    ll a[100010], b[100010];
    rep(i,0,N) cin >> a[i];
    rep(i,0,N) cin >> b[i];
    ll sumA = 0, sumB = 0;
    rep(i,0,N) sumA += a[i];
    rep(i,0,N) sumB += b[i];
    ll diff = N-2;
    if(N == 2){
        if(sumA == sumB){
            print(abs(a[0] - b[0]));
        }else{
            print(-1);
        }
        return;
    }
    if(sumA - sumB < 0){
        print(-1);
    }else if((sumA - sumB) % diff != 0){
        print(-1);
    }else{
        ll ans = (sumA - sumB) / diff;
        bool ok = true;
        rep(i,0,N){
            a[i] -= ans; 
        }
        ll v = 0;
        rep(i,0,N){
            if(b[i] - a[i] < 0 || (b[i] - a[i]) % 2 == 1){
                ok = false;
            }else{
                v += (b[i] - a[i]) / 2;
            }
        }
        if(ans != v) ok = false;
        if(ok){
            print(ans);
        }else{
            print(-1);
        }

    }

    

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0