結果

問題 No.1120 Strange Teacher
ユーザー fastmathfastmath
提出日時 2020-07-22 21:29:29
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 1,000 ms
コード長 1,466 bytes
コンパイル時間 5,115 ms
コンパイル使用メモリ 130,308 KB
実行使用メモリ 5,064 KB
最終ジャッジ日時 2023-09-04 15:22:46
合計ジャッジ時間 7,159 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 22 ms
4,672 KB
testcase_05 AC 22 ms
4,596 KB
testcase_06 AC 22 ms
4,584 KB
testcase_07 AC 22 ms
4,656 KB
testcase_08 AC 22 ms
4,600 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 21 ms
5,016 KB
testcase_11 AC 22 ms
5,052 KB
testcase_12 AC 22 ms
5,012 KB
testcase_13 AC 22 ms
5,000 KB
testcase_14 AC 22 ms
4,996 KB
testcase_15 AC 22 ms
5,064 KB
testcase_16 AC 22 ms
5,020 KB
testcase_17 AC 22 ms
5,016 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 24 ms
4,644 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 19 ms
4,620 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n;
    cin >> n;
    vector <int> a(n), b(n);

    int delt = 0;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        delt -= a[i];
    }   
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        delt += b[i];
    }   

    if (n == 2) {
        if (delt != 0)
            cout << -1 << endl;
        else
            cout << abs(a[0] - b[0]) << endl;
    }   
    else {

        if (delt > 0) {
            cout << -1 << endl;
            exit(0);
        }   

        if ((-delt)%(n - 2)) {
            cout << -1 << endl;
            exit(0);
        }   

        int k = (-delt)/(n-2);
        for (int i = 0; i < n; ++i) {
            if (abs(a[i] - b[i]) > k) {
                cout << -1 << endl;
                exit(0);
            }   

            if ((abs(a[i]-b[i])&1) ^ (k&1)) {
                cout << -1 << endl;
                exit(0);
            }   

        }
        cout << k << endl;
    }   

}
0