結果
問題 | No.1120 Strange Teacher |
ユーザー |
![]() |
提出日時 | 2020-07-23 00:34:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 69 ms / 1,000 ms |
コード長 | 1,288 bytes |
コンパイル時間 | 1,687 ms |
コンパイル使用メモリ | 169,000 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-23 03:06:43 |
合計ジャッジ時間 | 3,884 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long longtypedef pair<int,int> P;int INF = 1e9+7;int mod = 1e9+7;int dx[4] = {1, 0, -1, 0};int dy[4] = {0, 1, 0, -1};signed main() {int N;cin >> N;vector<int>A(N);vector<int>B(N);int sumA = 0;for(int i = 0; i < N; i++) {cin >> A[i];sumA+=A[i];}int sumB = 0;for(int i = 0; i < N; i++) {cin >> B[i];sumB+=B[i];}if(sumA < sumB) {cout << -1 << endl;return 0;}if(N == 2) {//%0はできないためif(sumA != sumB) cout << -1 << endl;else cout << abs(A[0]-B[0]) << endl;return 0;}if((sumA-sumB)%(N-2) != 0) {cout << -1 << endl;return 0;}int K = (sumA-sumB)/(N-2);int cnt = K;//後何回操作できるかfor(int i = 0; i < N; i++) {if(A[i]-K <= B[i]) {if((B[i]-(A[i]-K))/2 > cnt || (B[i]-(A[i]-K))%2 == 1) {cout << -1 << endl;return 0;}cnt-=(B[i]-(A[i]-K))/2;}else {cout << -1 << endl;return 0;}}if(cnt != 0) {cout << -1 << endl;}else {cout << K << endl;}}