結果

問題 No.1120 Strange Teacher
ユーザー le_panda_noirle_panda_noir
提出日時 2020-07-23 20:05:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,086 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 74,096 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 23:23:07
合計ジャッジ時間 2,893 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 56 ms
4,380 KB
testcase_05 AC 61 ms
4,376 KB
testcase_06 AC 57 ms
4,380 KB
testcase_07 AC 56 ms
4,376 KB
testcase_08 AC 57 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 54 ms
4,376 KB
testcase_11 AC 54 ms
4,376 KB
testcase_12 AC 55 ms
4,380 KB
testcase_13 AC 55 ms
4,376 KB
testcase_14 AC 55 ms
4,376 KB
testcase_15 AC 55 ms
4,376 KB
testcase_16 AC 56 ms
4,376 KB
testcase_17 AC 55 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 58 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using vi = vector<int>;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

int main() {
  int N;
  ins(N);

  vi A(N), B(N);
  ll sum = 0, sum2 = 0;
  rep(i, N) {
    cin >> A[i];
    sum += A[i];
  }
  rep(i, N) {
    cin >> B[i];
    sum2 += B[i];
  }
  int max_diff = -1e9;
  vi diff(N);
  rep(i, N) {
    max_diff = max(max_diff, A[i] - B[i]);
    diff[i] = A[i] - B[i];
    // if (diff[i] != 0)
    //   is_same = false;
  }
  // if (is_same) {
  //   cout << 0 << endl;
  //   return 0;
  // }
  ll sum_diff = 0;
  rep(i, N) {
    diff[i] -= max_diff;
    if (diff[i] % 2 != 0) {
      cout << -1 << endl;
      return 0;
    }
    sum_diff += abs(diff[i]) / 2;
  }
  if (sum_diff == max_diff)
    cout << max_diff << endl;
  else
    cout << -1 << endl;

  return 0;
}

// 全員-1して、ある生徒だけ+2と捉え直す。
// 全員0以下になるまで操作を行う。そこから+2していく
0