結果
問題 | No.1120 Strange Teacher |
ユーザー |
![]() |
提出日時 | 2020-07-22 21:32:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 33 ms / 1,000 ms |
コード長 | 1,089 bytes |
コンパイル時間 | 2,731 ms |
コンパイル使用メモリ | 194,796 KB |
最終ジャッジ日時 | 2025-01-12 02:15:39 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vec<ll> A(N),B(N); ll asum = 0,bsum = 0; for(auto& x:A){ cin >> x; asum += x; } for(auto& x:B){ cin >> x; bsum += x; } if(N==2){ ll d0 = A[0]-B[0],d1 = A[1]-B[1]; cout << ((d0+d1==0)? abs(d0):-1) << "\n"; return 0; } if(asum<bsum){ cout << -1 << "\n"; return 0; } if((asum-bsum)%(N-2)!=0){ cout << -1 << "\n"; return 0; } ll ans = (asum-bsum)/(N-2); ll cnt = 0; for(int i=0;i<N;i++){ ll d = B[i]-A[i]; if((ans+d)%2){ cout << -1 << "\n"; return 0; } if(ans+d<0){ cout << -1 << "\n"; return 0; } cnt += (ans+d)/2; } // cerr << ans << " " << cnt << "\n"; cout << (ans==cnt? ans:-1) << "\n"; }