結果

問題 No.1120 Strange Teacher
ユーザー umezoumezo
提出日時 2020-07-26 02:33:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 1,000 ms
コード長 657 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 200,056 KB
実行使用メモリ 4,896 KB
最終ジャッジ日時 2023-09-10 02:59:30
合計ジャッジ時間 4,922 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 7 ms
4,384 KB
testcase_04 AC 59 ms
4,752 KB
testcase_05 AC 60 ms
4,568 KB
testcase_06 AC 59 ms
4,616 KB
testcase_07 AC 60 ms
4,896 KB
testcase_08 AC 59 ms
4,756 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 60 ms
4,568 KB
testcase_11 AC 60 ms
4,624 KB
testcase_12 AC 60 ms
4,628 KB
testcase_13 AC 60 ms
4,572 KB
testcase_14 AC 59 ms
4,696 KB
testcase_15 AC 60 ms
4,576 KB
testcase_16 AC 60 ms
4,624 KB
testcase_17 AC 60 ms
4,568 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 66 ms
4,576 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 50 ms
4,752 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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