結果

問題 No.1120 Strange Teacher
ユーザー umezoumezo
提出日時 2020-07-26 02:33:44
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 1,000 ms
コード長 657 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 196,244 KB
最終ジャッジ日時 2025-01-12 05:45:49
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin>>n;
  
  vector<ll> A(n),B(n);
  ll a=0,b=0,x;
  rep(i,n){
    cin>>x;
    a+=x;
    A[i]=x;
  }
  rep(i,n){
    cin>>x;
    b+=x;
    B[i]=x;
  }
  
  if(n==2){
    if(a==b) cout<<abs(A[0]-B[0])<<endl;
    else cout<<-1<<endl;
    return 0;
  }
  
  if((a-b)%(n-2)!=0){
    cout<<-1<<endl;
    return 0;
  }
  
  ll k=(a-b)/(n-2);
  rep(i,n){
    ll t=B[i]-A[i]+k;
    if(t<0 || t%2==1){
      cout<<-1<<endl;
      return 0;
    }
  }
  
  cout<<k<<endl;
  
  return 0;
}
0