Submission #13209883


Source Code Expand

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N;
vector<int> A;

int func(int val) {
    int ret = 0;
    REP(i, N) {
        ret += abs(A[i] + val);
    }
    return ret;
}

signed main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    A.resize(N);
    int ans = 0;
    REP(i, N) { 
        cin >> A[i];
        A[i] -= (i + 1);
        ans += abs(A[i]);
    }
    if(ans == 0) {
        printf("0\n");
        return 0;
    }

    map<int, int> pat;
    REP(i, N) {
        pat[A[i]]++;
    }
    vector< pair<int, int> > v_pat;
    for(auto& tmp : pat) {
        v_pat.push_back(make_pair(tmp.second, tmp.first));
    }
    SORT(v_pat);
    reverse(v_pat.begin(), v_pat.end());

    int i_n = (v_pat.size() > 100) ? 100 : v_pat.size();
    REP(i, i_n) {
        ans = min(ans, func(-v_pat[i].second));
    }

    printf("%lld\n", ans);

    return 0;
}

Submission Info

Submission Time
Task C - Linear Approximation
User VTR
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1478 Byte
Status WA
Exec Time 154 ms
Memory 20080 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 4
AC × 11
WA × 8
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 WA 20 ms 3964 KB
subtask_1_03.txt WA 17 ms 3200 KB
subtask_1_04.txt WA 60 ms 9332 KB
subtask_1_05.txt WA 114 ms 17012 KB
subtask_1_06.txt AC 21 ms 1792 KB
subtask_1_07.txt WA 143 ms 19440 KB
subtask_1_08.txt WA 154 ms 19952 KB
subtask_1_09.txt WA 136 ms 20080 KB
subtask_1_10.txt WA 137 ms 19440 KB
subtask_1_11.txt AC 21 ms 1792 KB