結果

問題 No.738 平らな農地
ユーザー oshiborioshibori
提出日時 2018-09-28 23:08:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,895 bytes
コンパイル時間 1,747 ms
コンパイル使用メモリ 169,092 KB
実行使用メモリ 5,988 KB
最終ジャッジ日時 2024-04-20 11:57:35
合計ジャッジ時間 7,022 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 49 ms
5,376 KB
testcase_16 AC 51 ms
5,376 KB
testcase_17 AC 76 ms
5,552 KB
testcase_18 AC 74 ms
5,408 KB
testcase_19 AC 83 ms
5,724 KB
testcase_20 AC 53 ms
5,376 KB
testcase_21 AC 81 ms
5,732 KB
testcase_22 AC 52 ms
5,376 KB
testcase_23 AC 79 ms
5,704 KB
testcase_24 AC 77 ms
5,688 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 49 ms
5,376 KB
testcase_46 AC 48 ms
5,376 KB
testcase_47 AC 48 ms
5,376 KB
testcase_48 AC 44 ms
5,376 KB
testcase_49 AC 44 ms
5,376 KB
testcase_50 AC 47 ms
5,376 KB
testcase_51 AC 51 ms
5,376 KB
testcase_52 AC 46 ms
5,376 KB
testcase_53 AC 47 ms
5,376 KB
testcase_54 AC 50 ms
5,376 KB
testcase_55 AC 51 ms
5,376 KB
testcase_56 AC 52 ms
5,376 KB
testcase_57 AC 49 ms
5,376 KB
testcase_58 AC 48 ms
5,376 KB
testcase_59 AC 47 ms
5,376 KB
testcase_60 AC 47 ms
5,376 KB
testcase_61 AC 48 ms
5,376 KB
testcase_62 AC 45 ms
5,376 KB
testcase_63 AC 50 ms
5,376 KB
testcase_64 AC 48 ms
5,376 KB
testcase_65 AC 77 ms
5,688 KB
testcase_66 AC 80 ms
5,720 KB
testcase_67 WA -
testcase_68 AC 51 ms
5,376 KB
testcase_69 WA -
testcase_70 WA -
testcase_71 AC 12 ms
5,776 KB
testcase_72 AC 77 ms
5,548 KB
testcase_73 AC 49 ms
5,376 KB
testcase_74 AC 81 ms
5,712 KB
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 AC 87 ms
5,736 KB
testcase_79 AC 85 ms
5,612 KB
testcase_80 AC 55 ms
5,376 KB
testcase_81 AC 78 ms
5,552 KB
testcase_82 AC 83 ms
5,584 KB
testcase_83 AC 77 ms
5,612 KB
testcase_84 AC 77 ms
5,592 KB
testcase_85 WA -
testcase_86 WA -
testcase_87 AC 16 ms
5,376 KB
testcase_88 AC 15 ms
5,376 KB
testcase_89 AC 2 ms
5,376 KB
testcase_90 AC 2 ms
5,376 KB
testcase_91 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]) == typeid(INF) and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, 0, N) { cin >> A[i]; }
  auto f = [&](int k) {
    vector<int> v;
    int sum = 0;
    rep(i, 0, K) { sum += abs(A[i] - k); }
    v.eb(sum);
    rep(i, K, N) {
      sum += abs(A[i] - k);
      sum -= abs(A[i - K] - k);
      v.eb(sum);
    }
    return *min_element(all(v));
  };

  int l = 0, r = *max_element(all(A))+1;
  while (r - l > 1) {
    int m = (l + r) / 2;
    int x = f(m - 1), y = f(m);
    if (x < y)
      r = m;
    else
      l = m;
  }
  cout<<min(f(l),f(r))<<endl;

  return 0;
}
0