結果

問題 No.1120 Strange Teacher
ユーザー IKyoproIKyopro
提出日時 2020-07-22 21:32:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 1,089 bytes
コンパイル時間 1,947 ms
コンパイル使用メモリ 200,784 KB
実行使用メモリ 4,772 KB
最終ジャッジ日時 2023-09-04 15:41:48
合計ジャッジ時間 3,691 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 22 ms
4,628 KB
testcase_05 AC 22 ms
4,628 KB
testcase_06 AC 22 ms
4,536 KB
testcase_07 AC 21 ms
4,560 KB
testcase_08 AC 22 ms
4,564 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 21 ms
4,672 KB
testcase_11 AC 22 ms
4,552 KB
testcase_12 AC 22 ms
4,772 KB
testcase_13 AC 21 ms
4,564 KB
testcase_14 AC 21 ms
4,684 KB
testcase_15 AC 21 ms
4,652 KB
testcase_16 AC 22 ms
4,560 KB
testcase_17 AC 22 ms
4,612 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 23 ms
4,540 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 19 ms
4,564 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N),B(N);
    ll asum = 0,bsum = 0;
    for(auto& x:A){
        cin >> x;
        asum += x;
    }
    for(auto& x:B){
        cin >> x;
        bsum += x;
    }
    if(N==2){
        ll d0 = A[0]-B[0],d1 = A[1]-B[1];
        cout << ((d0+d1==0)? abs(d0):-1) << "\n";
        return 0;
    }
    if(asum<bsum){
        cout << -1 << "\n";
        return 0;
    }
    if((asum-bsum)%(N-2)!=0){
        cout << -1 << "\n";
        return 0;
    }
    ll ans = (asum-bsum)/(N-2);
    ll cnt = 0;
    for(int i=0;i<N;i++){
        ll d = B[i]-A[i];
        if((ans+d)%2){
            cout << -1 << "\n";
            return 0;
        }
        if(ans+d<0){
            cout << -1 << "\n";
            return 0;
        }
        cnt += (ans+d)/2;
    }
//    cerr << ans << " " << cnt << "\n";
    cout << (ans==cnt? ans:-1) << "\n";
}
0