結果

問題 No.1120 Strange Teacher
ユーザー HaaHaa
提出日時 2020-07-22 22:03:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,001 bytes
コンパイル時間 1,421 ms
コンパイル使用メモリ 167,476 KB
実行使用メモリ 5,648 KB
最終ジャッジ日時 2023-09-04 20:31:50
合計ジャッジ時間 3,687 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 8 ms
4,380 KB
testcase_04 AC 60 ms
5,648 KB
testcase_05 AC 60 ms
5,320 KB
testcase_06 AC 59 ms
5,324 KB
testcase_07 AC 60 ms
5,380 KB
testcase_08 AC 61 ms
5,632 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 62 ms
5,512 KB
testcase_11 AC 61 ms
5,456 KB
testcase_12 AC 61 ms
5,396 KB
testcase_13 AC 60 ms
5,368 KB
testcase_14 AC 60 ms
5,440 KB
testcase_15 AC 61 ms
5,372 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 67 ms
5,328 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 53 ms
5,508 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 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 aa(n), b(n); 
	REP(i,n) cin >> aa[i];
	REP(i,n) cin >> b[i];
	VI a=aa;
	bool up=0, no=0;
	ll ans=0;
	REP(i,n){
		if(aa[i]<b[i]){
			if(up){
				no=1;
				break;
			}
			ans+=b[i]-a[i];
			up=1;
			ll 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