結果

問題 No.1120 Strange Teacher
ユーザー shell_watarushell_wataru
提出日時 2020-07-22 22:15:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,467 bytes
コンパイル時間 6,729 ms
コンパイル使用メモリ 313,480 KB
実行使用メモリ 5,692 KB
最終ジャッジ日時 2023-09-04 21:11:18
合計ジャッジ時間 9,674 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 8 ms
4,352 KB
testcase_04 AC 61 ms
5,460 KB
testcase_05 AC 62 ms
5,356 KB
testcase_06 AC 61 ms
5,392 KB
testcase_07 AC 61 ms
5,336 KB
testcase_08 AC 61 ms
5,436 KB
testcase_09 AC 2 ms
4,360 KB
testcase_10 AC 61 ms
5,460 KB
testcase_11 AC 61 ms
5,460 KB
testcase_12 AC 61 ms
5,528 KB
testcase_13 AC 60 ms
5,356 KB
testcase_14 AC 60 ms
5,380 KB
testcase_15 AC 60 ms
5,332 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,356 KB
testcase_19 AC 68 ms
5,336 KB
testcase_20 AC 1 ms
4,356 KB
testcase_21 AC 1 ms
4,356 KB
testcase_22 AC 2 ms
4,360 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 52 ms
5,520 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,356 KB
testcase_27 AC 2 ms
4,356 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <ctime>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>
#include <string>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

int main()
{
  ll N;
  cin >> N;
  ll a_sum = 0;
  ll b_sum = 0;
  vector<ll> A(N);
  vector<ll> B(N);
  for (size_t i = 0; i < N; i++)
  {
      cin >> A[i];
      a_sum += A[i];
  }
  for (size_t i = 0; i < N; i++)
  {
      cin >> B[i];
      b_sum += B[i];
  }

  ll total = 0;
  vector<ll> diffs(N);
  for (size_t i = 0; i < N; i++)
  {
      diffs[i] = B[i] - A[i];
      total += B[i] - A[i];
  }
  if (N == 2){
      if (total == 0){
        ll positive_sum = 0;
        for(int i = 0; i < N;i++){
            if (diffs[i] > 0){
                positive_sum += diffs[i];
            }
        }
        cout << positive_sum << endl;
      }else{
          cout << -1 << endl;
      }
  }else{
    // cout << total % (N-2) << endl;
    if (total % (N-2) != 0){
        cout << -1 << endl;
    }else{
        bool can_make = true;
        for(int i = 0; i < N;i++){
            diffs[i] = diffs[i] + total/(N-2);
            if (diffs[i] > 0 || abs(diffs[i]) % 2 != 0){
                can_make = false;
            }
        }
        if (can_make){
            cout << - total/(N-2) << endl;;
        }else{
            cout << -1 << endl;
        }
    }

  }
  return 0;
}
0