結果

問題 No.1120 Strange Teacher
ユーザー poohbearpoohbear
提出日時 2020-07-23 21:01:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 200,016 KB
実行使用メモリ 4,944 KB
最終ジャッジ日時 2023-09-06 00:36:15
合計ジャッジ時間 4,973 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 60 ms
4,556 KB
testcase_05 AC 59 ms
4,516 KB
testcase_06 AC 59 ms
4,644 KB
testcase_07 AC 59 ms
4,656 KB
testcase_08 AC 59 ms
4,552 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 60 ms
4,556 KB
testcase_11 AC 61 ms
4,852 KB
testcase_12 AC 60 ms
4,580 KB
testcase_13 AC 60 ms
4,652 KB
testcase_14 AC 59 ms
4,600 KB
testcase_15 AC 59 ms
4,828 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 66 ms
4,620 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 51 ms
4,572 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 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 ci = a[i]-b[i]+c;
        if(ci<0||ci%2==1){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << c << endl;
    return 0;
}
0