Submission #81511

# Submission time Handle Problem Language Result Execution time Memory
81511 2018-10-25T07:41:19 Z luckyboy Krov (COCI17_krov) C++14
70 / 140
1500 ms 3772 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];
        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 50 ms 504 KB Output is correct
2 Correct 61 ms 744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 744 KB Output is correct
2 Correct 60 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 788 KB Output is correct
2 Correct 147 ms 812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 892 KB Output is correct
2 Correct 183 ms 916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 1040 KB Output is correct
2 Correct 363 ms 1040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1531 ms 1040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1549 ms 1284 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1569 ms 1676 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1580 ms 2568 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1572 ms 3772 KB Time limit exceeded
2 Halted 0 ms 0 KB -