結果

問題 No.1120 Strange Teacher
ユーザー 0w10w1
提出日時 2020-12-19 14:04:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,068 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 207,996 KB
実行使用メモリ 4,548 KB
最終ジャッジ日時 2023-10-21 09:10:52
合計ジャッジ時間 5,466 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N; { cin >> N; } 

  vector<int> A(N); { for (int i = 0; i < N; ++i) cin >> A[i]; }

  vector<int> B(N); { for (int i = 0; i < N; ++i) cin >> B[i]; }

  if (N == 2) {
    if (A[0] - B[0] == B[1] - A[0]) {
      cout << abs(A[0] - B[0]) << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }

  int dSum = 0; {
    for (int i = 0; i < N; ++i) dSum += A[i] - B[i];
  }

  if (dSum < 0 || dSum % (N - 2)) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> dord(N); {
    iota(dord.begin(), dord.end(), 0);
    sort(dord.begin(), dord.end(), [&](int i, int j) { return B[i] - A[i] > B[j] - A[j]; });
  }

  int dGlobal = 0;
  int opCnt = dSum / (N - 2);
  for (int i : dord) {
    int d = B[i] - (A[i] - dGlobal);
    int q = (opCnt + d) / 2;

    if (opCnt + d % 2 == 1 || q < 0 || opCnt < q) {
      cout << -1 << endl;
      return 0;
    }
    
    opCnt -= q;
    dGlobal += q;
  }

  assert(opCnt == 0);
  cout << (dSum / (N - 2)) << endl;
}

0