Submission #2766850


Source Code Expand

Copy
#include<bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
typedef long long ll;
int n,a[200001],b;
ll ans;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        a[i]-=i;
    }
    sort(a+1,a+n+1);
    b=a[(n+1)/2];
    for(int i=1;i<=n;i++)
       ans+=abs(a[i]-b);
    cout<<ans<<endl;
    return 0;
}

Submission Info

Submission Time
Task C - Linear Approximation
User hsl2363
Language C++14 (GCC 5.4.1)
Score 300
Code Size 370 Byte
Status AC
Exec Time 37 ms
Memory 1024 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:12:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^

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 13 ms 640 KB
subtask_1_05.txt AC 23 ms 896 KB
subtask_1_06.txt AC 25 ms 1024 KB
subtask_1_07.txt AC 37 ms 1024 KB
subtask_1_08.txt AC 26 ms 1024 KB
subtask_1_09.txt AC 26 ms 1024 KB
subtask_1_10.txt AC 26 ms 1024 KB
subtask_1_11.txt AC 26 ms 1024 KB