結果

問題 No.1120 Strange Teacher
ユーザー bachoppibachoppi
提出日時 2020-07-22 23:15:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,283 bytes
コンパイル時間 1,916 ms
コンパイル使用メモリ 100,180 KB
実行使用メモリ 6,672 KB
最終ジャッジ日時 2023-09-05 04:15:24
合計ジャッジ時間 3,802 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 8 ms
4,380 KB
testcase_04 AC 63 ms
6,544 KB
testcase_05 AC 63 ms
6,672 KB
testcase_06 AC 61 ms
6,540 KB
testcase_07 AC 63 ms
6,484 KB
testcase_08 AC 62 ms
6,460 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 68 ms
6,556 KB
testcase_11 AC 69 ms
6,560 KB
testcase_12 AC 69 ms
6,512 KB
testcase_13 AC 63 ms
6,612 KB
testcase_14 AC 63 ms
6,464 KB
testcase_15 AC 63 ms
6,664 KB
testcase_16 AC 63 ms
6,512 KB
testcase_17 AC 61 ms
6,496 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 69 ms
6,448 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 54 ms
6,604 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 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)) can=false;
  if(can) cout << sum/(n-2) << endl;
  else cout << -1 << endl;
}
  
0