結果

問題 No.1120 Strange Teacher
ユーザー bachoppibachoppi
提出日時 2020-07-23 09:56:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 1,000 ms
コード長 1,304 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 99,188 KB
実行使用メモリ 6,664 KB
最終ジャッジ日時 2023-09-05 22:04:12
合計ジャッジ時間 3,427 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 64 ms
6,472 KB
testcase_05 AC 63 ms
6,460 KB
testcase_06 AC 63 ms
6,540 KB
testcase_07 AC 62 ms
6,464 KB
testcase_08 AC 63 ms
6,468 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 69 ms
6,460 KB
testcase_11 AC 70 ms
6,520 KB
testcase_12 AC 70 ms
6,456 KB
testcase_13 AC 65 ms
6,664 KB
testcase_14 AC 65 ms
6,520 KB
testcase_15 AC 63 ms
6,604 KB
testcase_16 AC 64 ms
6,472 KB
testcase_17 AC 63 ms
6,472 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 69 ms
6,464 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 54 ms
6,524 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

  
  
   

int main(){
  int n; cin >> n; ll a[n], b[n], sa[n];
  rep(i, n){
    cin >> a[i];
  }
  rep(i, n){
    cin >> b[i];
  }
  ll sum = 0;
  rep(i, n){
    sa[i] = a[i]-b[i]; sum+=sa[i];
  }
  if(n==2){
    if(sum!=0) cout << -1 << endl;
    else cout << abs(sa[0]) << endl;
    return 0;
  }
  bool can = true;
  if(sum%(n-2)!=0) can = false;
  if(sum<0) can = false;
  //cout << can << endl;
  rep(i, n-1){
    if(abs(sa[i])%2!=abs(sa[i+1])%2) can=false;
  }
  sort(sa, sa+n, greater<>()); ll kai[n]; kai[0] = 0; ll k = 0;
  rep(i, n-1){
    kai[i+1] = kai[i]+(sa[i]-sa[i+1])/2; k+=kai[i+1]; //cout << kai[i+1] << endl;
  }
  if(k>sum/(n-2) || ((sum/(n-2))-k)%n!=0) can=false;
  if(can) cout << sum/(n-2) << endl;
  else cout << -1 << endl;
}
0