結果

問題 No.1120 Strange Teacher
ユーザー kyoprounokyoprouno
提出日時 2020-07-23 01:19:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 1,000 ms
コード長 1,417 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 175,728 KB
実行使用メモリ 4,860 KB
最終ジャッジ日時 2023-09-05 08:07:18
合計ジャッジ時間 4,751 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 8 ms
4,380 KB
testcase_04 AC 60 ms
4,724 KB
testcase_05 AC 60 ms
4,720 KB
testcase_06 AC 59 ms
4,860 KB
testcase_07 AC 60 ms
4,620 KB
testcase_08 AC 60 ms
4,624 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 61 ms
4,716 KB
testcase_11 AC 60 ms
4,552 KB
testcase_12 AC 60 ms
4,860 KB
testcase_13 AC 60 ms
4,724 KB
testcase_14 AC 60 ms
4,724 KB
testcase_15 AC 59 ms
4,556 KB
testcase_16 AC 59 ms
4,724 KB
testcase_17 AC 59 ms
4,560 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 65 ms
4,612 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 52 ms
4,704 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n),b(n);
    ll sum_a=0,sum_b=0,sum_c=0;
    rep(i,n){
        cin >> a[i];
        sum_a+=a[i];
    }
    rep(i,n){
        cin >> b[i];
        sum_b+=b[i];
    }
    if(n==2){
        ll d0=a[0]-b[0];
        ll d1=b[1]-a[1];
        if(d0==d1){
            cout << abs(d0) << endl;
        }
        else{
            cout << -1 << endl;
        }
        return 0;
    }
    ll cnt=(sum_a-sum_b)/(n-2); //操作回数の和
    bool ok=true;
    rep(i,n){
        ll x=cnt+b[i]-a[i];
        if(x%2==1  || x<0){
            ok=false;
            break;
        }
        else{
            sum_c+=(x/2);
        }
        
    }
    if(sum_c!=cnt) ok=false;
    if(ok) cout << cnt << endl;
    else cout << -1 << endl;
    return 0;
}
0