結果

問題 No.1120 Strange Teacher
ユーザー kawara_y_kyoprokawara_y_kyopro
提出日時 2020-07-22 21:46:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,353 bytes
コンパイル時間 2,715 ms
コンパイル使用メモリ 104,504 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-04 17:09:58
合計ジャッジ時間 2,796 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 21 ms
4,376 KB
testcase_11 AC 20 ms
4,376 KB
testcase_12 AC 21 ms
4,376 KB
testcase_13 AC 20 ms
4,376 KB
testcase_14 AC 20 ms
4,380 KB
testcase_15 AC 20 ms
4,380 KB
testcase_16 AC 20 ms
4,376 KB
testcase_17 AC 20 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 22 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 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 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int bcnt = 0, bi;
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        if (b[i] > a[i]) bcnt++, bi = i;
    }
    if (bcnt == 0) {
        if (a == b) cout << 0 << '\n';
        else cout << -1 << '\n';
    } else if (bcnt > 1) {
        cout << -1 << '\n';
    } else {
        int minus = b[bi] - a[bi];
        bcnt = 0;
        int bi2;
        for (int i = 0; i < n; i++) {
            if (i != bi && b[i] + minus == a[i]) bcnt++, bi2 = i;
        }
        if (bcnt == n - 1) cout << minus << '\n';
        else if (bcnt != 1) cout << -1 << '\n';
        else {
            int ab = INF;
            for (int i = 0; i < n; i++) {
                if (i == bi || i == bi2) continue;
                if (ab == INF) ab = (a[i] - b[i] - minus);
                else {
                    if (ab != (a[i] - b[i] - minus)) {
                        cout << -1 << '\n';
                        return 0;
                    }
                }
            }
            if (ab & 1) cout << -1 << '\n';
            else cout << minus + ab << '\n';
        }
    }
    return 0;
}
0