結果

問題 No.1120 Strange Teacher
ユーザー catuppercatupper
提出日時 2020-07-22 21:29:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 1,000 ms
コード長 1,194 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 82,892 KB
実行使用メモリ 5,112 KB
最終ジャッジ日時 2023-09-04 15:17:23
合計ジャッジ時間 3,217 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 61 ms
4,956 KB
testcase_05 AC 61 ms
4,904 KB
testcase_06 AC 60 ms
4,932 KB
testcase_07 AC 60 ms
4,932 KB
testcase_08 AC 60 ms
4,904 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 61 ms
4,936 KB
testcase_11 AC 60 ms
4,904 KB
testcase_12 AC 61 ms
4,948 KB
testcase_13 AC 60 ms
5,040 KB
testcase_14 AC 60 ms
4,916 KB
testcase_15 AC 60 ms
4,920 KB
testcase_16 AC 60 ms
4,896 KB
testcase_17 AC 60 ms
5,112 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 66 ms
4,972 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 51 ms
4,908 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;


void ok(){
    cout << "Yes" << endl;
    exit(0);
}

void ng(){
    cout <<  "-1" << endl;
    exit(0);
}

Int n;
Int a[110000], b[110000];
Int ans;
int main(){
    cin >> n;
    Int suma = 0, sumb = 0;
    for(int i = 0;i < n;i++){cin >> a[i];suma += a[i];}
    for(int i = 0;i < n;i++){cin >> b[i];sumb += b[i];}
    if(n == 2){
        if(suma != sumb)ng();
        cout << abs(a[0] - b[0]) << endl;
        return 0;
    }
    if((suma - sumb) % (n-2) != 0)ng();
    if(suma < sumb)ng();
    Int cnt = (suma - sumb) / (n-2);
    for(int i = 0;i < n;i++){
        Int dif = b[i] - (a[i] - cnt);
        if(dif < 0)ng();
        if(dif % 2 == 1)ng();
        ans += dif / 2;
    }
    cout << ans << endl;
    
    return 0;
}
0