結果

問題 No.1120 Strange Teacher
ユーザー definedefine
提出日時 2020-07-22 21:35:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 1,000 ms
コード長 1,094 bytes
コンパイル時間 3,650 ms
コンパイル使用メモリ 197,392 KB
実行使用メモリ 5,096 KB
最終ジャッジ日時 2023-09-04 15:57:51
合計ジャッジ時間 4,925 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 60 ms
5,088 KB
testcase_05 AC 60 ms
4,904 KB
testcase_06 AC 59 ms
4,888 KB
testcase_07 AC 60 ms
4,896 KB
testcase_08 AC 60 ms
5,096 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 61 ms
4,948 KB
testcase_11 AC 61 ms
4,852 KB
testcase_12 AC 60 ms
4,976 KB
testcase_13 AC 60 ms
4,900 KB
testcase_14 AC 60 ms
4,972 KB
testcase_15 AC 60 ms
4,940 KB
testcase_16 AC 59 ms
4,840 KB
testcase_17 AC 60 ms
4,900 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 66 ms
4,892 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 51 ms
4,896 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 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<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 998244353;
constexpr int inf = 3e18;

int N,A[100005],B[100005];
signed main(){
	cin>>N;
	int sum1=0,sum2=0;
	rep(i,N){
		cin>>A[i];sum1+=A[i];
	}
	int mx=0;
	bool even=false,odd=false;
	rep(i,N){
		cin>>B[i];sum2+=B[i];
		chmax(mx,abs(B[i]-A[i]));
		if(abs(B[i]-A[i])%2)odd=true;
		else even=true;
	}
	if(N==2){
		if(sum1==sum2)cout<<mx<<endl;
		else cout<<"-1\n";
		return 0;
	}
	if(sum1<sum2)cout<<"-1"<<endl;
	else if((sum1-sum2)%(N-2))cout<<"-1\n";
	else {
		int ans=(sum1-sum2)/(N-2);
		if(ans<mx)cout<<"-1\n";
		else if(ans%2==0&&odd)cout<<"-1\n";
		else if(ans%2&&even)cout<<"-1\n";
		else cout<<ans<<endl;
	}
}
0