結果

問題 No.1120 Strange Teacher
ユーザー ats5515ats5515
提出日時 2020-07-22 21:28:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 981 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 146,172 KB
実行使用メモリ 4,720 KB
最終ジャッジ日時 2023-09-04 15:16:41
合計ジャッジ時間 3,099 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 22 ms
4,564 KB
testcase_05 AC 22 ms
4,720 KB
testcase_06 AC 22 ms
4,624 KB
testcase_07 AC 22 ms
4,620 KB
testcase_08 AC 22 ms
4,652 KB
testcase_09 WA -
testcase_10 AC 21 ms
4,664 KB
testcase_11 AC 22 ms
4,608 KB
testcase_12 AC 21 ms
4,640 KB
testcase_13 AC 22 ms
4,656 KB
testcase_14 AC 21 ms
4,620 KB
testcase_15 AC 22 ms
4,548 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 23 ms
4,664 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 19 ms
4,560 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 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 res = 0;
	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;
					}
					c += t / 2;
				}
				if (c != tot) {
					ok = false;
				}

				if (ok) {
					cout << tot << endl;
				}
			}
			if (!ok) {
				cout << -1 << endl;
			}
		}
	}
}
0