Submission #2766833


Source Code Expand

Copy
#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n;
  vector<LL> a, b;

  Solver(LL n) : n(n), a(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    b = a;
    for (int i = 0; i < n; ++i) {
      b[i] -= i + 1;
    }
    sort(b.begin(), b.end());
    LL m = b[n / 2];
    DBG(m)
    LL ans = 0;
    for (int i = 0; i < n; ++i) {
      ans += abs(a[i] - m - i - 1);
    }
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}

Submission Info

Submission Time
Task C - Linear Approximation
User Hoi_koro
Language C++14 (GCC 5.4.1)
Score 300
Code Size 917 Byte
Status AC
Exec Time 35 ms
Memory 3456 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
sample_04.txt AC 1 ms 256 KB
subtask_1_01.txt AC 1 ms 256 KB
subtask_1_02.txt AC 7 ms 896 KB
subtask_1_03.txt AC 5 ms 768 KB
subtask_1_04.txt AC 12 ms 1792 KB
subtask_1_05.txt AC 21 ms 2944 KB
subtask_1_06.txt AC 23 ms 3328 KB
subtask_1_07.txt AC 35 ms 3456 KB
subtask_1_08.txt AC 24 ms 3456 KB
subtask_1_09.txt AC 24 ms 3328 KB
subtask_1_10.txt AC 24 ms 3328 KB
subtask_1_11.txt AC 24 ms 3328 KB