結果

問題 No.1120 Strange Teacher
ユーザー HaaHaa
提出日時 2020-07-22 21:55:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 989 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 167,356 KB
実行使用メモリ 4,904 KB
最終ジャッジ日時 2023-09-04 18:19:25
合計ジャッジ時間 3,992 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 8 ms
4,384 KB
testcase_04 AC 60 ms
4,904 KB
testcase_05 AC 61 ms
4,608 KB
testcase_06 AC 60 ms
4,728 KB
testcase_07 AC 61 ms
4,564 KB
testcase_08 AC 60 ms
4,736 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 60 ms
4,652 KB
testcase_11 AC 61 ms
4,704 KB
testcase_12 AC 61 ms
4,672 KB
testcase_13 AC 60 ms
4,608 KB
testcase_14 AC 59 ms
4,640 KB
testcase_15 AC 59 ms
4,728 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 65 ms
4,724 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,384 KB
testcase_24 AC 51 ms
4,640 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 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;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int n; cin >> n;
	VI a(n), b(n); 
	REP(i,n) cin >> a[i];
	REP(i,n) cin >> b[i];
	bool up=0, no=0;
	ll ans=0;
	REP(i,n){
		if(a[i]<b[i]){
			if(up){
				no=1;
				break;
			}
			ans+=b[i]-a[i];
			up=1;
			int d=b[i]-a[i];
			REP(j,n)
				a[j]-=d;
			a[i]=b[i];
		}
	}
	if(no){
		cout << -1 << endl;
		return 0;
	}
	ll down=0;
	REP(i,n)
		down+=a[i]-b[i];
	if(n==2){
		if(down==0)
			cout << ans << endl;
		else
			cout << -1 << endl;
	}
	else{
		if(down%(n-2)==0){
			ll k=down/(n-2);
			ll kk=0;
			REP(i,n){
				if((k-(a[i]-b[i]))%2)
					no=1;
				kk+=(k-(a[i]-b[i]))/2;
			}
			if(no||kk!=k)
				cout << -1 << endl;
			else
				cout << ans+k << endl;
		}
		else
			cout << -1 << endl;
	}
	return 0;
}
0