Submission #81513

# Submission time Handle Problem Language Result Execution time Memory
81513 2018-10-25T07:44:23 Z luckyboy Krov (COCI17_krov) C++14
84 / 140
1500 ms 1396 KB
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 100005
#define maxm 500005
#define pii pair <int,int>
#define Task "Krov"
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,a[maxn],b[maxn];
long long ans = 1ll*maxc*maxc;
int main()
{
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    read(n);
    FOR(i,1,n) read(a[i]);
    FOR(i,1,n)
    {
        FOR(j,1,n)
        {
            b[j] = a[j] + abs(i-j);
        }
//        sort(b+1,b+n+1);
//        int temp = b[n - n / 2];
        nth_element(b+1,b+n-n/2,b+n+1);
        int temp = b[n - n / 2];
        temp = max(temp,max(i,n-i+1));
        long long cur = 0;
        FOR(j,1,n)
        {
            int ww = temp - abs(i-j);
            cur += abs(ww - a[j]);
        }
        ans = min(ans,cur);
    }
    write(ans);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 376 KB Output is correct
2 Correct 16 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 424 KB Output is correct
2 Correct 15 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 468 KB Output is correct
2 Correct 32 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 600 KB Output is correct
2 Correct 43 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 704 KB Output is correct
2 Correct 92 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 303 ms 716 KB Output is correct
2 Correct 173 ms 852 KB Output is correct
3 Correct 51 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1578 ms 852 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1578 ms 1012 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1553 ms 1268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1566 ms 1396 KB Time limit exceeded
2 Halted 0 ms 0 KB -