結果
問題 | No.1120 Strange Teacher |
ユーザー |
![]() |
提出日時 | 2020-07-22 22:24:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 1,000 ms |
コード長 | 1,102 bytes |
コンパイル時間 | 2,073 ms |
コンパイル使用メモリ | 194,916 KB |
最終ジャッジ日時 | 2025-01-12 03:11:12 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} using Int = long long; const char newl = '\n'; template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); Int n; cin>>n; if(n==2){ Int a1,a2,b1,b2; cin>>a1>>a2>>b1>>b2; if(a1+a2!=b1+b2) drop(-1); cout<<abs(a1-b1)<<newl; return 0; } vector<Int> as(n),bs(n); for(Int i=0;i<n;i++) cin>>as[i]; for(Int i=0;i<n;i++) cin>>bs[i]; Int sa=accumulate(as.begin(),as.end(),0LL); Int sb=accumulate(bs.begin(),bs.end(),0LL); if(sa<sb) drop(-1); Int dif=sa-sb; if(dif%(n-2)) drop(-1); dif/=n-2; vector<Int> cs(n); for(Int i=0;i<n;i++){ // bs[i] = as[i] + 2 * cs[i] - dif cs[i]=bs[i]-(as[i]-dif); if(cs[i]&1) drop(-1); if(cs[i]<0) drop(-1); cs[i]/=2; } Int sc=accumulate(cs.begin(),cs.end(),0LL); if(sc!=dif) drop(-1); drop(dif); return 0; }