結果

問題 No.1120 Strange Teacher
ユーザー ats5515ats5515
提出日時 2020-07-22 21:48:56
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,047 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 146,232 KB
実行使用メモリ 5,084 KB
最終ジャッジ日時 2023-09-04 17:33:36
合計ジャッジ時間 5,062 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 21 ms
4,560 KB
testcase_11 AC 21 ms
4,652 KB
testcase_12 AC 21 ms
4,572 KB
testcase_13 AC 22 ms
4,656 KB
testcase_14 AC 21 ms
4,568 KB
testcase_15 AC 21 ms
4,660 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	int sumA = 0;
	int sumB = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sumA += A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
		sumB += B[i];
	}
	if (N == 2) {
		if (sumA != sumB) {
			cout << -1 << endl;
		} else {
			cout << abs(A[0] - B[0]) << endl;
		}
	} else {
		bool ok = true;
		if (sumA < sumB) {
			ok = false;
		} else {
			int k = sumA - sumB;
			if (k % (N - 2) != 0) {
				ok = false;
			} else {
				int tot = k / (N - 2);
				int c = 0;
				for (int i = 0; i < N; i++) {
					int t = (B[i] - A[i] + tot);
					if (t % 2 != 0) {
						ok = false;
					}
					int x = t / 2;
					A[i] += x - (tot - x);
					c += x;
				}
				if (c != tot) {
					ok = false;
				}
				
				if (ok) {
					assert(false);
					cout << tot << endl;
					return 0;
				}
			}
		}
		if (!ok) {
			cout << -1 << endl;
		}
	}
}
0