結果

問題 No.1120 Strange Teacher
ユーザー startcppstartcpp
提出日時 2020-07-22 21:30:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 1,000 ms
コード長 910 bytes
コンパイル時間 1,830 ms
コンパイル使用メモリ 69,912 KB
実行使用メモリ 5,860 KB
最終ジャッジ日時 2023-09-04 15:28:03
合計ジャッジ時間 3,123 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 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,860 KB
testcase_05 AC 60 ms
5,808 KB
testcase_06 AC 60 ms
5,668 KB
testcase_07 AC 61 ms
5,668 KB
testcase_08 AC 60 ms
5,692 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 60 ms
4,904 KB
testcase_11 AC 60 ms
4,916 KB
testcase_12 AC 61 ms
4,944 KB
testcase_13 AC 59 ms
4,892 KB
testcase_14 AC 60 ms
4,948 KB
testcase_15 AC 60 ms
4,948 KB
testcase_16 AC 59 ms
4,984 KB
testcase_17 AC 60 ms
5,068 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 67 ms
5,692 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 52 ms
5,680 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[100000];
int b[100000];
int c[100000];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	
	int sumA = 0;
	rep(i, n) sumA += a[i];
	
	int sumB = 0;
	rep(i, n) sumB += b[i];
	
	//N = 2の解法
	if (n == 2) {
		if (sumA != sumB) {
			cout << -1 << endl;
		}
		else {
			cout << abs(a[0] - b[0]) << endl;
		}
		return 0;
	}
	
	//N >= 3の解法
	if (sumA - sumB < 0 || (sumA - sumB) % (n - 2) != 0) {
		cout << -1 << endl;
		return 0;
	}
	
	int T = (sumA - sumB) / (n - 2);
	int cst = 0;
	rep(i, n) {
		c[i] = a[i] - b[i] - T;
		if (c[i] > 0 || (-c[i]) % 2 == 1) {
			cout << -1 << endl;
			return 0;
		}
		cst += (-c[i]) / 2;
	}
	
	if (cst != T) {
		cout << -1 << endl;
		return 0;
	}
	
	cout << T << endl;
	return 0;
}
0