結果

問題 No.1120 Strange Teacher
ユーザー abc3abc3
提出日時 2020-07-23 05:44:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 1,000 ms
コード長 1,249 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 170,064 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 15:59:15
合計ジャッジ時間 3,825 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
4,376 KB
testcase_04 AC 58 ms
4,380 KB
testcase_05 AC 58 ms
4,380 KB
testcase_06 AC 57 ms
4,376 KB
testcase_07 AC 58 ms
4,380 KB
testcase_08 AC 58 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 58 ms
4,376 KB
testcase_11 AC 57 ms
4,380 KB
testcase_12 AC 58 ms
4,376 KB
testcase_13 AC 58 ms
4,376 KB
testcase_14 AC 58 ms
4,380 KB
testcase_15 AC 57 ms
4,380 KB
testcase_16 AC 58 ms
4,376 KB
testcase_17 AC 58 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 63 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 49 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N;
  cin>>N;
  vector<int>A(N),B(N);
  int64_t sa=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    sa+=A[i];
  }
  int64_t sb=0;
  for(int i=0;i<N;i++){
    cin>>B[i];
    sb+=B[i];
  }
  if(N>=3){
    if(sb>sa){cout<<-1<<endl;}
    else if((sa-sb)%(N-2)==0){
      int64_t t=abs(sa-sb)/(N-2);
      bool ok=true;
      for(int i=0;i<N;i++){
        int64_t q=abs(A[i]-B[i]);
        if(t<q||(B[i]-A[i]+t)%2!=0){ok=false;}
      }
      if(ok){cout<<t<<endl;}
      else{cout<<-1<<endl;}
    }
    else{cout<<-1<<endl;}
  }
  else if(N==2){
    if(sa==sb){cout<<abs(A[0]-B[0])<<endl;}
    else{cout<<-1<<endl;}
  }
  else{cout<<-1<<endl;}
  return 0;
}
0