結果

問題 No.1120 Strange Teacher
ユーザー divinediscon10tdivinediscon10t
提出日時 2020-07-23 00:27:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 1,119 bytes
コンパイル時間 1,575 ms
コンパイル使用メモリ 164,728 KB
実行使用メモリ 5,124 KB
最終ジャッジ日時 2023-09-05 06:38:33
合計ジャッジ時間 3,439 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    ll a[n]; zep(i, 0, n)cin >> a[i];
    ll b[n]; zep(i, 0, n)cin >> b[i];
    
    if(n == 2){
    	if(a[0] + a[1] == b[0] + b[1]){
    		print(abs(a[0] - b[0]))
    	}else{
    		print(-1)
    	}
    	return 0;
    }
    
    ll sm = 0;
    zep(i, 0, n){
    	sm += a[i] - b[i];
    }
    
    if(sm < 0 || sm % (n - 2) != 0){
    	print(-1) return 0;
    }
    
    ll x = sm / (n - 2);
    
    ll cnt = 0;
    zep(i, 0, n){
    	ll y = x - (a[i] - b[i]);
    	if(y % 2 != 0 || y < 0){print(-1) return 0;}
    	cnt += y / 2;
    }
    
    if(cnt == x){
    	print(x)
    }else{
    	print(-1)
    }
    
    return 0;
}
0