結果

問題 No.1120 Strange Teacher
ユーザー kappybarkappybar
提出日時 2020-07-25 12:10:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 952 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 167,664 KB
実行使用メモリ 4,712 KB
最終ジャッジ日時 2023-09-09 08:58:03
合計ジャッジ時間 4,601 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_04 AC 61 ms
4,648 KB
testcase_05 AC 60 ms
4,544 KB
testcase_06 AC 59 ms
4,544 KB
testcase_07 AC 60 ms
4,712 KB
testcase_08 AC 60 ms
4,544 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 60 ms
4,592 KB
testcase_11 AC 61 ms
4,616 KB
testcase_12 AC 61 ms
4,544 KB
testcase_13 AC 60 ms
4,540 KB
testcase_14 AC 60 ms
4,600 KB
testcase_15 AC 60 ms
4,616 KB
testcase_16 AC 60 ms
4,608 KB
testcase_17 AC 60 ms
4,612 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 66 ms
4,616 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 51 ms
4,600 KB
testcase_25 RE -
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 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

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];
    rep(i,n) sumb += b[i];

    if((suma-sumb)%(n-2)!=0||suma<sumb){
        cout << -1 << endl;
        return 0;
    }

    ll ans = (suma-sumb)/(n-2);

    ll sum = 0;
    bool ok = true;

    rep(i,n){
        if((b[i]-a[i]+ans)%2!=0||(b[i]-a[i]+ans)<0){
            ok = false;
            break;
        }
        else{
            sum += (b[i]-a[i]+ans)/2;
        }
    }

    if(ok&&sum==ans) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}
0