結果

問題 No.1120 Strange Teacher
コンテスト
ユーザー pockyny
提出日時 2020-07-22 21:43:25
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 62 ms / 1,000 ms
コード長 868 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 611 ms
コンパイル使用メモリ 81,260 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-11 14:48:02
合計ジャッジ時間 2,742 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>

using namespace std;
typedef long long ll;
ll a[100010],b[100010];
int main(){
    int i; ll n; cin >> n;
    for(i=0;i<n;i++) cin >> a[i];
    for(i=0;i<n;i++) cin >> b[i];
    ll s1 = 0,s2 = 0;
    for(i=0;i<n;i++){
        s1 += a[i]; s2 += b[i];
    }
    if(n==2){
        if(a[0] + a[1]==b[0] + b[1]){
            cout << max(b[1] - a[1],a[1] - b[1]) << endl; 
        }else{
            cout << -1 << endl;
        }
        return 0;
    }
    if(s1<s2 || (s1 - s2)%(n - 2)!=0){
        cout << -1 << endl;
        return 0;
    }
    ll t = (s1 - s2)/(n - 2),tt = 0;
    for(i=0;i<n;i++){
        if((b[i] - a[i] + t<0) || (b[i] - a[i] + t)&1){
            cout << -1 << endl;
            return 0;
        }
        tt += (b[i] - a[i] + t)/2;
    }
    if(tt==t){
        cout << t << endl;
    }else{
        cout << -1 << endl;
    }
}
0