結果

問題 No.1120 Strange Teacher
ユーザー shell_watarushell_wataru
提出日時 2020-07-22 22:08:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,759 bytes
コンパイル時間 6,550 ms
コンパイル使用メモリ 314,620 KB
実行使用メモリ 5,620 KB
最終ジャッジ日時 2023-09-04 20:46:32
合計ジャッジ時間 9,175 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
4,376 KB
testcase_04 AC 62 ms
5,388 KB
testcase_05 AC 62 ms
5,368 KB
testcase_06 AC 61 ms
5,428 KB
testcase_07 AC 61 ms
5,528 KB
testcase_08 AC 61 ms
5,340 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 61 ms
5,344 KB
testcase_11 AC 61 ms
5,436 KB
testcase_12 AC 61 ms
5,420 KB
testcase_13 AC 60 ms
5,368 KB
testcase_14 AC 60 ms
5,488 KB
testcase_15 AC 60 ms
5,344 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 68 ms
5,404 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 53 ms
5,384 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,384 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 changes = 0;
        ll current = 0;
        for(int i = 0; i < N;i++){
            if (current > 0 && diffs[i] < 0){
                changes += min(abs(current),abs(diffs[i]));
                current +=  diffs[i];
            }else if (current < 0 && diffs[i] > 0){
                changes += min(abs(current),abs(diffs[i]));
                current +=  diffs[i];
            }else{
                current +=  diffs[i];
            }
        }
        cout << changes << 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