Submission #2793786


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




int N, A[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) {
        cin >> A[i];
        A[i] -= (i + 1);
    }
    sort(A, A + N);

    int b;
    if (N % 2 == 1) b = A[N / 2];
    else b = (A[N / 2 - 1] + A[N / 2]) / 2;

    ll ans = 0;
    rep(i, 0, N) ans += abs(A[i] - b);
    cout << ans << endl;
}

Submission Info

Submission Time
Task C - Linear Approximation
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1679 Byte
Status AC
Exec Time 34 ms
Memory 1024 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 384 KB
subtask_1_03.txt AC 5 ms 384 KB
subtask_1_04.txt AC 12 ms 640 KB
subtask_1_05.txt AC 20 ms 896 KB
subtask_1_06.txt AC 23 ms 1024 KB
subtask_1_07.txt AC 34 ms 1024 KB
subtask_1_08.txt AC 23 ms 1024 KB
subtask_1_09.txt AC 23 ms 1024 KB
subtask_1_10.txt AC 23 ms 1024 KB
subtask_1_11.txt AC 23 ms 1024 KB