Submission #2769736


Source Code Expand

Copy
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (auto &v : a) cin >> v;
    
    ll sum = 0;
    for (auto i = 0; i < n; i++) {
        sum += a[i] - i;
    }
    auto ave = sum / n;
    
    ll ans1 = 0;
    for (auto i = 0; i < n; i++) {
        ans1 += abs(a[i] - (ave + i));
    }
    ll ans2 = 0;
    auto ave2 = ave + 1;
    for (auto i = 0; i < n; i++) {
        ans2 += abs(a[i] - (ave2 + i));
    }
    ll ans3 = 0;
    auto ave3 = ave - 1;
    for (auto i = 0; i < n; i++) {
        ans3 += abs(a[i] - (ave3 + i));
    }
    cout << min(min(ans1, ans2), ans3) << endl;
    
}

Submission Info

Submission Time
Task C - Linear Approximation
User MatsuTaku
Language C++14 (GCC 5.4.1)
Score 0
Code Size 965 Byte
Status WA
Exec Time 81 ms
Memory 1792 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 4
AC × 13
WA × 6
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 16 ms 512 KB
subtask_1_03.txt WA 14 ms 512 KB
subtask_1_04.txt WA 40 ms 1024 KB
subtask_1_05.txt AC 70 ms 1664 KB
subtask_1_06.txt AC 78 ms 1792 KB
subtask_1_07.txt WA 80 ms 1792 KB
subtask_1_08.txt WA 80 ms 1792 KB
subtask_1_09.txt WA 80 ms 1792 KB
subtask_1_10.txt AC 81 ms 1792 KB
subtask_1_11.txt AC 80 ms 1792 KB