結果

問題 No.1120 Strange Teacher
ユーザー beetbeet
提出日時 2020-07-22 22:24:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 1,102 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 200,852 KB
実行使用メモリ 5,796 KB
最終ジャッジ日時 2023-09-04 21:32:29
合計ジャッジ時間 4,294 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 4 ms
4,384 KB
testcase_04 AC 23 ms
5,732 KB
testcase_05 AC 22 ms
5,704 KB
testcase_06 AC 22 ms
5,684 KB
testcase_07 AC 22 ms
5,728 KB
testcase_08 AC 22 ms
5,740 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 22 ms
4,908 KB
testcase_11 AC 22 ms
4,964 KB
testcase_12 AC 22 ms
5,000 KB
testcase_13 AC 21 ms
4,912 KB
testcase_14 AC 22 ms
4,960 KB
testcase_15 AC 22 ms
4,952 KB
testcase_16 AC 22 ms
5,772 KB
testcase_17 AC 22 ms
5,796 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 23 ms
5,792 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 21 ms
5,736 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 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;

  if(n==2){
    Int a1,a2,b1,b2;
    cin>>a1>>a2>>b1>>b2;
    if(a1+a2!=b1+b2) drop(-1);
    cout<<abs(a1-b1)<<newl;
    return 0;
  }

  vector<Int> as(n),bs(n);
  for(Int i=0;i<n;i++) cin>>as[i];
  for(Int i=0;i<n;i++) cin>>bs[i];

  Int sa=accumulate(as.begin(),as.end(),0LL);
  Int sb=accumulate(bs.begin(),bs.end(),0LL);

  if(sa<sb) drop(-1);
  Int dif=sa-sb;
  if(dif%(n-2)) drop(-1);
  dif/=n-2;

  vector<Int> cs(n);
  for(Int i=0;i<n;i++){
    // bs[i] = as[i] + 2 * cs[i] - dif
    cs[i]=bs[i]-(as[i]-dif);
    if(cs[i]&1) drop(-1);
    if(cs[i]<0) drop(-1);
    cs[i]/=2;
  }
  Int sc=accumulate(cs.begin(),cs.end(),0LL);
  if(sc!=dif) drop(-1);

  drop(dif);
  return 0;
}
0