結果
| 問題 | No.1120 Strange Teacher |
| コンテスト | |
| ユーザー |
kg_curry57
|
| 提出日時 | 2020-07-22 22:09:14 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 1,000 ms |
| コード長 | 1,949 bytes |
| コンパイル時間 | 14,949 ms |
| コンパイル使用メモリ | 280,840 KB |
| 最終ジャッジ日時 | 2025-01-12 02:55:14 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
using namespace std;
using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}
const double PI = acos(-1);
constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}
class Task{
public:
void solve(istream& in, ostream& out){
int N;
in>>N;
lint sa = 0, sb = 0;
vc<int> A(N), B(N);
REP(i, N) in>>A[i], sa += A[i];
REP(i, N) in>>B[i], sb += B[i];
if(N==2){
if(sa==sb) out<<abs(A[0]-B[0])<<'\n';
else out<<"-1\n";
return;
}else if(sb>sa or (sa-sb)%(N-2)!=0){
out<<"-1\n";
return;
}
bool ok = true;
lint x = (sa-sb) / (N-2), y = 0;
REP(i, N){
if(B[i]-A[i]+x<0 or (B[i]-A[i]+x)%2==1){
ok = false;
break;
}
y += (B[i]-A[i]+x) / 2;
}
if(ok and x==y) out<<x<<'\n';
else out<<"-1\n";
}
};
int main(){
istream& in(cin);
ostream& out(cout);
ios_base::sync_with_stdio(false);
in.tie(nullptr), out.tie(nullptr);
Task solver;
solver.solve(in, out);
return 0;
}
kg_curry57