結果
問題 | No.1120 Strange Teacher |
ユーザー |
|
提出日時 | 2024-10-02 02:30:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 1,000 ms |
コード長 | 746 bytes |
コンパイル時間 | 1,886 ms |
コンパイル使用メモリ | 194,548 KB |
最終ジャッジ日時 | 2025-02-24 14:27:32 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int N;cin>>N;ll S=0;vector<ll> A(N);for(int i=0;i<N;i++){cin>>A[i];}for(int i=0;i<N;i++){ll a;cin>>a;A[i]=a-A[i];S+=A[i];}if(N==2){cout<<(S==0?abs(A[0]):-1)<<endl;}else{if(S>0||abs(S)%(N-2)!=0){cout<<-1<<endl;return 0;}ll D=(abs(S)/(N-2));bool OK=1;ll K=0;for(int i=0;i<N;i++){A[i]+=D;if(A[i]<0||A[i]%2!=0)OK=0;K+=(A[i]/2);}cout<<(OK&&K==D?D:-1)<<endl;}}