結果

問題 No.1120 Strange Teacher
ユーザー ats5515ats5515
提出日時 2020-07-22 22:23:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 1,036 bytes
コンパイル時間 1,212 ms
コンパイル使用メモリ 146,336 KB
実行使用メモリ 4,788 KB
最終ジャッジ日時 2023-09-04 21:30:19
合計ジャッジ時間 3,054 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 21 ms
4,524 KB
testcase_05 AC 22 ms
4,616 KB
testcase_06 AC 21 ms
4,696 KB
testcase_07 AC 22 ms
4,680 KB
testcase_08 AC 21 ms
4,540 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 21 ms
4,676 KB
testcase_11 AC 22 ms
4,624 KB
testcase_12 AC 21 ms
4,788 KB
testcase_13 AC 21 ms
4,696 KB
testcase_14 AC 22 ms
4,784 KB
testcase_15 AC 21 ms
4,528 KB
testcase_16 AC 22 ms
4,680 KB
testcase_17 AC 22 ms
4,708 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 23 ms
4,676 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 19 ms
4,564 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 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 < 0 || t % 2 != 0) {
						ok = false;
					}
					int x = t / 2;
					A[i] += x - (tot - x);
					c += x;
				}
				if (c != tot) {
					ok = false;
				}
				
				if (ok) {
					cout << tot << endl;
					return 0;
				}
			}
		}
		if (!ok) {
			cout << -1 << endl;
		}
	}
}
0