結果

問題 No.1120 Strange Teacher
ユーザー kg_curry57kg_curry57
提出日時 2020-07-22 22:09:14
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 1,000 ms
コード長 1,949 bytes
コンパイル時間 2,893 ms
コンパイル使用メモリ 222,292 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-04 20:50:10
合計ジャッジ時間 4,992 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

const double PI = acos(-1);
constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class Task{
public:
    void solve(istream& in, ostream& out){
        int N;
        in>>N;
        lint sa = 0, sb = 0;
        vc<int> A(N), B(N);
        REP(i, N) in>>A[i], sa += A[i];
        REP(i, N) in>>B[i], sb += B[i];
        if(N==2){
            if(sa==sb) out<<abs(A[0]-B[0])<<'\n';
            else out<<"-1\n";
            return;
        }else if(sb>sa or (sa-sb)%(N-2)!=0){
            out<<"-1\n";
            return;
        }
        bool ok = true;
        lint x = (sa-sb) / (N-2), y = 0;
        REP(i, N){
            if(B[i]-A[i]+x<0 or (B[i]-A[i]+x)%2==1){
                ok = false;
                break;
            }
            y += (B[i]-A[i]+x) / 2;
        }
        if(ok and x==y) out<<x<<'\n';
        else out<<"-1\n";
    }
};

int main(){
    istream& in(cin);
    ostream& out(cout);
    ios_base::sync_with_stdio(false);
    in.tie(nullptr), out.tie(nullptr);
    Task solver;
    solver.solve(in, out);
    return 0;
}
0