結果

問題 No.1120 Strange Teacher
ユーザー CyanmondCyanmond
提出日時 2020-07-22 22:24:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,745 bytes
コンパイル時間 1,166 ms
コンパイル使用メモリ 122,824 KB
実行使用メモリ 5,624 KB
最終ジャッジ日時 2023-09-04 21:31:39
合計ジャッジ時間 3,586 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 63 ms
5,456 KB
testcase_05 AC 62 ms
5,328 KB
testcase_06 AC 62 ms
5,332 KB
testcase_07 AC 63 ms
5,548 KB
testcase_08 AC 62 ms
5,496 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 68 ms
5,484 KB
testcase_11 AC 69 ms
5,376 KB
testcase_12 AC 69 ms
5,464 KB
testcase_13 AC 64 ms
5,624 KB
testcase_14 AC 63 ms
5,336 KB
testcase_15 AC 62 ms
5,548 KB
testcase_16 AC 64 ms
5,468 KB
testcase_17 AC 63 ms
5,332 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 68 ms
5,596 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	ll n;
	cin >> n;
	vl a(n);
	vl b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	ll ca = 0;
	ll cb = 0;
	for (int i = 0; i < n; i++) {
		ca += a[i];
		cb += b[i];
	}
	ll count = 0;
	vl ja(n);
	for (int i = 0; i < n; i++) {
		ja[i] = b[i] - a[i];
	}
	ll you = 0;
	bool hantei = false;
	sort(ja.begin(), ja.end());
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans = abs(ja[0]);
		you = ja[i] - ja[0];
		count += you;
	}
	if (count == ans*2) hantei = true;;
	ll siagea = 0;
	ll siageb = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] > b[i]) {
			siageb += a[i] - b[i];
		}
		else {
			siagea += b[i] - a[i];
		}
	}
	if (hantei) {
		cout << ans << endl;
	}
	else cout << -1 << endl;
}
0