結果

問題 No.1120 Strange Teacher
ユーザー totori_nyaatotori_nyaa
提出日時 2020-07-22 21:42:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,434 bytes
コンパイル時間 3,269 ms
コンパイル使用メモリ 199,316 KB
実行使用メモリ 5,144 KB
最終ジャッジ日時 2023-09-04 16:44:22
合計ジャッジ時間 5,342 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    ll a[n],b[n];
    ll sum = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum += a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        sum -= b[i];
    }
    if(n == 2){
        if(a[0] >= b[0] && a[1]<=b[1] && a[0]-b[0] == b[1]-a[1])cout << b[1] - a[1] << endl;
        else if(a[0] <= b[0] && a[1] >= b[1] && a[1]-b[1] == b[0]-a[0])cout << b[0] - a[0] << endl;
        else cout << -1 << endl;
        return 0;
    }
    // sum -= (n-2)*k
    if(sum % (n-2)){
        cout << "-1\n";
        return 0;
    }
    ll now = 0;
    int cnt = 0;
    int cnt2=0;
    bool pos = 1;
    for(int i=0;i<n;i++){
        if(a[i] < b[i]){
            now += b[i]-a[i];
            cnt++;
        }
        else if(a[i]-b[i] < sum/(n-2)){
            cnt2++;
            if((a[i]-b[i])%2)pos=false;
            now += a[i]-b[i];
        }
        if(sum/(n-2) < a[i]-b[i])pos=false;
    }
    if(cnt > 1 || cnt2>1 || now>sum/(n-2) || !pos)cout << -1 << endl;
    else cout << sum / (n-2) << endl;
}
0