結果

問題 No.1120 Strange Teacher
ユーザー ぷらぷら
提出日時 2020-07-23 00:25:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,255 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 167,576 KB
実行使用メモリ 4,908 KB
最終ジャッジ日時 2023-09-05 06:36:21
合計ジャッジ時間 4,254 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 65 ms
4,792 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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 << 0 << endl;
        return 0;
    }
    if(N == 2) {//%0はできないため
        if(sumA != sumB) cout << 0 << endl;
        else cout << abs(A[0]-B[0]) << endl;
        return 0;
    }
    if((sumA-sumB)%(N-2) != 0) {
        cout << 0 << 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 << 0 << endl;
                return 0;
            }
            cnt-=(B[i]-(A[i]-K))/2;
        }
        else {
            cout << 0 << endl;
            return 0;
        }
    }
    if(cnt != 0) {
        cout << 0 << endl;
    }
    else {
        cout << K << endl;
    }
}
0