Submission #81511

#TimeUsernameProblemLanguageResultExecution timeMemory
81511luckyboyKrov (COCI17_krov)C++14
70 / 140
1580 ms3772 KiB
/**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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...