結果

問題 No.1120 Strange Teacher
ユーザー 沙耶花沙耶花
提出日時 2020-07-22 21:28:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 1,000 ms
コード長 858 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 204,444 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 13:35:22
合計ジャッジ時間 4,293 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000002


int main(){
	
	long long N;
	cin>>N;
	
	vector<long long> A(N),B(N);
	long long SA = 0LL,SB = 0LL;
	for(int i=0;i<N;i++){
		cin>>A[i];
		SA += A[i];
	}
	
	for(int i=0;i<N;i++){
		cin>>B[i];
		SB += B[i];
	}
	
	if(SB>SA){
		cout<<-1<<endl;
		return 0;
	}
	if(N!=2&&(SA-SB)%(N-2)!=0){
		cout<<-1<<endl;
		return 0;
	}
	if(N==2&&SA!=SB){
		cout<<-1<<endl;
		return 0;
	}
	
	if(N==2){
		cout<<abs(A[0]-B[0])<<endl;
	}
	else{
		long long t = (SA-SB)/(N-2);
		for(int i=0;i<N;i++){
			A[i] -= t;
		}
		long long cnt = 0LL;
		for(int i=0;i<N;i++){
			if(B[i]<A[i]||(B[i]-A[i])%2!=0){
				cout<<-1<<endl;
				return 0;
			}
			else{
				cnt += (B[i]-A[i])/2;
			}
		}
		cout<<cnt<<endl;
	}
	
	return 0;
}
0