結果

問題 No.1120 Strange Teacher
ユーザー kenken714kenken714
提出日時 2020-07-24 20:52:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 66 ms / 1,000 ms
コード長 1,200 bytes
コンパイル時間 2,146 ms
コンパイル使用メモリ 146,232 KB
実行使用メモリ 4,848 KB
最終ジャッジ日時 2023-09-08 02:34:55
合計ジャッジ時間 6,322 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
4,376 KB
testcase_04 AC 57 ms
4,588 KB
testcase_05 AC 56 ms
4,684 KB
testcase_06 AC 56 ms
4,664 KB
testcase_07 AC 57 ms
4,584 KB
testcase_08 AC 58 ms
4,592 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 58 ms
4,584 KB
testcase_11 AC 59 ms
4,616 KB
testcase_12 AC 59 ms
4,612 KB
testcase_13 AC 57 ms
4,692 KB
testcase_14 AC 57 ms
4,544 KB
testcase_15 AC 58 ms
4,584 KB
testcase_16 AC 59 ms
4,584 KB
testcase_17 AC 60 ms
4,632 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 66 ms
4,848 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 50 ms
4,592 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    REP(i,n){
        cin >> a[i];
    }
    REP(i,n){
        cin >> b[i];
    }
    ll suma = 0, sumb = 0;
    REP(i, n){
        suma += a[i];
        sumb += b[i];
    }
    if(n == 2){
        if (suma != sumb) cout << -1 << endl;
        else cout << abs(a[0] - b[0]) << endl;
        return 0;
    }
    if((suma - sumb) % (n - 2) != 0){
        cout << -1<< endl;
        return 0;
    }
    ll k = (suma - sumb) / (n - 2);
    if(k < 0){
        cout << -1 << endl;
        return 0;
    }
    REP(i, n){
        a[i] -= k;
        if(b[i] < a[i] or (b[i] - a[i]) % 2 == 1 or b[i] > a[i] + 2 * k){
            cout << -1<< endl;
            return 0;
        }
    }
    cout << k << endl;
}
0