結果

問題 No.1120 Strange Teacher
ユーザー poohbearpoohbear
提出日時 2020-07-23 21:14:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 1,000 ms
コード長 1,145 bytes
コンパイル時間 1,891 ms
コンパイル使用メモリ 201,008 KB
実行使用メモリ 4,816 KB
最終ジャッジ日時 2023-09-06 00:45:08
合計ジャッジ時間 4,241 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 7 ms
4,376 KB
testcase_04 AC 59 ms
4,636 KB
testcase_05 AC 57 ms
4,560 KB
testcase_06 AC 55 ms
4,616 KB
testcase_07 AC 59 ms
4,572 KB
testcase_08 AC 57 ms
4,628 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 58 ms
4,588 KB
testcase_11 AC 59 ms
4,636 KB
testcase_12 AC 57 ms
4,608 KB
testcase_13 AC 54 ms
4,700 KB
testcase_14 AC 55 ms
4,628 KB
testcase_15 AC 56 ms
4,680 KB
testcase_16 AC 58 ms
4,812 KB
testcase_17 AC 55 ms
4,816 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 62 ms
4,692 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 46 ms
4,696 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
typedef vector<vector<ll> > Graph;
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 = 1e18;

int main(){
    int n;
    cin >> n;
    vector<ll>a(n),b(n);
    ll sa=0,sb=0;
    rep(i,n){
        cin>>a[i];
        sa+=a[i];
    }
    rep(i,n){
        cin>>b[i];
        sb+=b[i];
    }
    if(sa<sb){
        cout << -1 << endl;
        return 0;
    }
    if(n==2){
        if((sa+sb)%2==0){
            cout << abs(a[0]-b[0]) << endl;
            return 0;
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }
    if((sa-sb)%(n-2)!=0){
        cout << -1 << endl;
        return 0;
    }
    ll c = (sa-sb)/(n-2);
    rep(i,n){
        ll t = b[i]-(a[i]-c);
        if(t<0||t%2==1){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << c << endl;
    return 0;
}
0