結果

問題 No.1120 Strange Teacher
ユーザー ぷらぷら
提出日時 2020-07-23 00:30:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 1,000 ms
コード長 1,262 bytes
コンパイル時間 3,646 ms
コンパイル使用メモリ 167,364 KB
実行使用メモリ 4,852 KB
最終ジャッジ日時 2023-09-05 06:43:10
合計ジャッジ時間 4,339 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 8 ms
4,380 KB
testcase_04 AC 59 ms
4,564 KB
testcase_05 AC 59 ms
4,576 KB
testcase_06 AC 59 ms
4,728 KB
testcase_07 AC 60 ms
4,580 KB
testcase_08 AC 60 ms
4,576 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 60 ms
4,852 KB
testcase_11 AC 61 ms
4,576 KB
testcase_12 AC 60 ms
4,524 KB
testcase_13 AC 60 ms
4,724 KB
testcase_14 AC 60 ms
4,724 KB
testcase_15 AC 60 ms
4,580 KB
testcase_16 AC 59 ms
4,668 KB
testcase_17 AC 60 ms
4,756 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 67 ms
4,752 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 50 ms
4,528 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<int>A(N);
    vector<int>B(N);
    int sumA = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sumA+=A[i];
    }
    int sumB = 0;
    for(int i = 0; i < N; i++) {
        cin >> B[i];
        sumB+=B[i];
    }
    if(sumA < sumB) {
        cout << -1 << endl;
        return 0;
    }
    if(N == 2) {//%0はできないため
        if(sumA != sumB) cout << -1 << endl;
        else cout << abs(A[0]-B[0]) << endl;
        return 0;
    }
    if((sumA-sumB)%(N-2) != 0) {
        cout << -1 << endl;
        return 0;
    }
    int K = (sumA-sumB)/(N-2);
    int cnt = K;//後何回操作できるか
    for(int i = 0; i < N; i++) {
        if(A[i]-K <= B[i]) {
            if((B[i]-(A[i]-K))/2 > cnt) {
                cout << -1 << endl;
                return 0;
            }
            cnt-=(B[i]-(A[i]-K))/2;
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }
    if(cnt != 0) {
        cout << -1 << endl;
    }
    else {
        cout << K << endl;
    }
}
0