結果

問題 No.1120 Strange Teacher
ユーザー shell_mugshell_mug
提出日時 2020-07-22 21:34:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,067 bytes
コンパイル時間 1,939 ms
コンパイル使用メモリ 110,564 KB
実行使用メモリ 4,748 KB
最終ジャッジ日時 2023-09-04 15:48:51
合計ジャッジ時間 2,714 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 22 ms
4,604 KB
testcase_05 AC 21 ms
4,548 KB
testcase_06 AC 22 ms
4,524 KB
testcase_07 AC 22 ms
4,580 KB
testcase_08 AC 22 ms
4,724 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 21 ms
4,520 KB
testcase_11 AC 22 ms
4,676 KB
testcase_12 AC 22 ms
4,564 KB
testcase_13 AC 22 ms
4,632 KB
testcase_14 AC 22 ms
4,700 KB
testcase_15 AC 21 ms
4,568 KB
testcase_16 AC 22 ms
4,632 KB
testcase_17 AC 22 ms
4,676 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 23 ms
4,604 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 19 ms
4,748 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n), b(n);
    rep (i, a.size()) cin >> a[i];
    rep (i, b.size()) cin >> b[i];
    ll diff = 0, k;
    rep (i, n) diff += a[i] - b[i];
    if (diff < 0 || (n != 2 && diff % (n - 2))) {
        cout << "-1\n";
        return 0;
    }
    if (n != 2) {
        k = diff / (n - 2);
        eprintf("k: %lld\n", k);
        bool ok = true;
        rep (i, n) {
            ll c = b[i] - a[i] + k;
            if (c < 0 || c % 2) ok = false;
        }
        cout << (ok ? k : -1) << "\n";
    } else {
        if (a[0] + a[1] == b[0] + b[1] && !((a[0] - b[0]) % 2)) {
            cout << abs(a[0] - b[0]) / 2 << "\n";
        } else {
            cout << "-1\n";
        }
    }
    return 0;
}
0