結果

問題 No.1120 Strange Teacher
ユーザー Kome_soudouKome_soudou
提出日時 2022-11-11 18:41:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 1,000 ms
コード長 903 bytes
コンパイル時間 2,948 ms
コンパイル使用メモリ 166,412 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-10-11 14:44:16
合計ジャッジ時間 6,750 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 7 ms
4,348 KB
testcase_04 AC 58 ms
4,868 KB
testcase_05 AC 58 ms
4,560 KB
testcase_06 AC 58 ms
4,668 KB
testcase_07 AC 58 ms
4,752 KB
testcase_08 AC 59 ms
4,628 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 58 ms
4,640 KB
testcase_11 AC 58 ms
4,888 KB
testcase_12 AC 59 ms
4,688 KB
testcase_13 AC 58 ms
4,692 KB
testcase_14 AC 58 ms
4,680 KB
testcase_15 AC 58 ms
4,560 KB
testcase_16 AC 58 ms
4,752 KB
testcase_17 AC 58 ms
4,676 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 63 ms
4,628 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 49 ms
4,752 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> a(n);
	vector<int64_t> b(n);
	int64_t as = 0;
	int64_t bs = 0;
	for(int64_t i = 0; i < n; i++)
	{
		cin >> a[i];
		as += a[i];
	}
	for(int64_t i = 0; i < n; i++)
	{
		cin >> b[i];
		bs += b[i];
	}
	
	if(as - bs < 0)
	{
		cout << -1 << endl;
		return 0;
	}
	if(n == 2)
	{
		if(as != bs) cout << -1 << endl;
		else cout << abs(a[0] - b[0]) << endl;
		return 0;
	}
	
	if((as - bs) % (n - 2) != 0)
	{
		cout << -1 << endl;
		return 0;
	}
	
	int64_t k = (as - bs) / (n - 2);
	for(int64_t i = 0; i < n; i++) a[i] -= k;
	int64_t cnt = 0;
	for(int64_t i = 0; i < n; i++)
	{
		if(a[i] > b[i])
		{
			cout << -1 << endl;
			return 0;
		}
		if((b[i] - a[i]) % 2 != 0)
		{
			cout << -1 << endl;
			return 0;
		}
		cnt += (b[i] - a[i]) / 2;
	}
	if(k == cnt) cout << k << endl;
	else cout << -1 << endl;
	return 0;
}
0