結果
問題 | No.1120 Strange Teacher |
ユーザー |
![]() |
提出日時 | 2020-07-22 22:03:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,001 bytes |
コンパイル時間 | 1,485 ms |
コンパイル使用メモリ | 170,748 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 18:04:36 |
合計ジャッジ時間 | 3,414 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 2 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long int ll;typedef pair<ll, ll> P;typedef vector<ll> VI;typedef vector<VI> VVI;const ll MOD = 1000000007;const ll INF = 1e18;#define REP(i, n) for (int i = 0; i < n; i++)#define ALL(v) v.begin(), v.end()int main(){int n; cin >> n;VI aa(n), b(n);REP(i,n) cin >> aa[i];REP(i,n) cin >> b[i];VI a=aa;bool up=0, no=0;ll ans=0;REP(i,n){if(aa[i]<b[i]){if(up){no=1;break;}ans+=b[i]-a[i];up=1;ll d=b[i]-a[i];REP(j,n)a[j]-=d;a[i]=b[i];}}if(no){cout << -1 << endl;return 0;}ll down=0;REP(i,n)down+=a[i]-b[i];if(n==2){if(down==0)cout << ans << endl;elsecout << -1 << endl;}else{if(down%(n-2)==0){ll k=down/(n-2);ll kk=0;REP(i,n){if((k-(a[i]-b[i]))%2)no=1;kk+=(k-(a[i]-b[i]))/2;}if(no||kk!=k)cout << -1 << endl;elsecout << ans+k << endl;}elsecout << -1 << endl;}return 0;}