結果

問題 No.1120 Strange Teacher
ユーザー cn_449cn_449
提出日時 2020-07-23 10:22:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 1,000 ms
コード長 1,906 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 114,220 KB
実行使用メモリ 5,532 KB
最終ジャッジ日時 2023-09-05 22:04:40
合計ジャッジ時間 2,720 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 22 ms
5,496 KB
testcase_05 AC 22 ms
5,480 KB
testcase_06 AC 22 ms
5,464 KB
testcase_07 AC 22 ms
5,372 KB
testcase_08 AC 22 ms
5,532 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 21 ms
4,632 KB
testcase_11 AC 21 ms
4,580 KB
testcase_12 AC 22 ms
4,608 KB
testcase_13 AC 21 ms
4,576 KB
testcase_14 AC 21 ms
4,568 KB
testcase_15 AC 21 ms
4,568 KB
testcase_16 AC 22 ms
5,368 KB
testcase_17 AC 22 ms
5,476 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 24 ms
5,452 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 20 ms
5,484 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	ll sa = 0, sb = 0;
	rep(i, n) {
		cin >> a[i];
		sa += a[i];
	}
	rep(i, n) {
		cin >> b[i];
		sb += b[i];
	}
	if (sa < sb) {
		cout << "-1\n";
		return 0;
	}
	ll ans = sa - sb;
	if (n > 2) {
		if (ans % (n - 2)) {
			cout << "-1\n";
			return 0;
		}
	}
	else {
		if (ans) cout << "-1\n";
		else cout << abs(a[0] - b[0]) << '\n';
		return 0;
	}
	if (n > 2) ans /= n - 2;
	vector<ll> c(n);
	rep(i, n) c[i] = b[i] - a[i];
	rep(i, n) {
		if ((c[i] + ans) & 1) {
			cout << "-1\n";
			return 0;
		}
		else {
			c[i] += ans;
			c[i] /= 2;
			if (c[i] < 0) {
				cout << "-1\n";
				return 0;
			}
		}
	}
	cout << ans << '\n';
}
0