結果
問題 |
No.1120 Strange Teacher
|
ユーザー |
👑 |
提出日時 | 2023-06-27 13:43:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 77 ms / 1,000 ms |
コード長 | 871 bytes |
コンパイル時間 | 568 ms |
コンパイル使用メモリ | 72,548 KB |
最終ジャッジ日時 | 2025-02-15 02:35:50 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <iostream> #include <vector> using namespace std; int main(){ long long n;cin>>n; vector<long long> A(n), B(n); for(int i = 0; n > i; i++){ cin>>A[i]; } for(int i = 0; n > i; i++){ cin>>B[i]; } if(n == 2){ if(A[0]+A[1] == B[0]+B[1]){ cout << abs(A[0]-B[0]) << endl; }else{ cout << -1 << endl; } }else{ long long dif = 0; for(int i = 0; n > i; i++){ dif += A[i]-B[i]; } if((dif < 0) || (dif%(n-2))){ cout << -1 << endl; return 0; } long long c = dif/(n-2); long long nw = 0; for(int i = 0; n > i; i++){ long long mn = A[i]-c; if((B[i]-mn < 0) || (B[i]-mn)%2){ cout << -1 << endl; return 0; } nw += (B[i]-mn)/2; } if(nw == c){ cout << c << endl; }else{ cout << -1 << endl; } } } //611 155k