結果

問題 No.1120 Strange Teacher
ユーザー shiomusubi496shiomusubi496
提出日時 2020-07-22 21:42:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 1,000 ms
コード長 683 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 166,348 KB
実行使用メモリ 5,528 KB
最終ジャッジ日時 2023-09-04 16:45:59
合計ジャッジ時間 3,914 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 61 ms
5,324 KB
testcase_05 AC 61 ms
5,436 KB
testcase_06 AC 60 ms
5,328 KB
testcase_07 AC 60 ms
5,368 KB
testcase_08 AC 61 ms
5,476 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 62 ms
5,492 KB
testcase_11 AC 61 ms
5,368 KB
testcase_12 AC 61 ms
5,388 KB
testcase_13 AC 60 ms
5,364 KB
testcase_14 AC 60 ms
5,328 KB
testcase_15 AC 61 ms
5,364 KB
testcase_16 AC 59 ms
5,424 KB
testcase_17 AC 63 ms
5,468 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 66 ms
5,324 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 51 ms
5,528 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int N,g=0;
    cin>>N;
    vector<int> A(N),B(N),C(N);
    for(int i=0;i<N;i++)cin>>A[i];
    for(int i=0;i<N;i++){
        cin>>B[i];
        C[i]=B[i]-A[i];
        g-=C[i];
    }
    if(g<0){
        puts("-1");
        return 0;
    }
    if(N==2){
        if(A[0]-B[0]!=B[1]-A[1])puts("-1");
        else cout<<abs(A[0]-B[0]);
        return 0;
    }
    int M=g/(N-2),ans=0;
    for(int i=0;i<N;i++){
        if((M-abs(C[i]))%2!=0 || M<abs(C[i])){
            puts("-1");
            return 0;
        }
        ans+=(M-abs(C[i]))/2;
        if(C[i]>0)ans+=C[i];
    }
    cout<<ans<<endl;
}
0