Submission #166758

# Submission time Handle Problem Language Result Execution time Memory
166758 2019-12-03T18:24:22 Z theStaticMind Krov (COCI17_krov) C++14
0 / 140
1500 ms 3704 KB
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n;
      cin>>n;
      vector<int>arr(n);
      for(int i=0;i<n;i++)cin>>arr[i];
      for(int i=0;i<n;i++)arr[i]--;
      vector<int>L(n,arr[0]);
      vector<int>R(n,arr[0]);
      for(int i=1;i<n;i++){
            L[i]=L[i-1]+arr[i]-i;
            R[i]=R[i-1]+arr[i]+i;
      }
      int ans=INF;
      for(int i=0;i<n;i++){
            long double sum=L[i]+(i+1)+R[n-1]-R[i]-(n-i-1);
            sum=sum/n;
            int mn=max(i,n-i-1);
            int down=sum;
            int up=ceil(sum);
            down=max(down,mn);
            up=max(up,mn);
            int a=0,b=0;
            for(int j=0;j<=i;j++){
                  a+=labs(down-(arr[j]-j+i));
                  b+=labs(up-(arr[j]-j+i));
            }
            for(int j=i+1;j<n;j++){
                  a+=labs(down-(arr[j]+j-i));
                  b+=labs(up-(arr[j]+j-i));
            }
            ans=min(ans,min(a,b));
      }
      cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1412 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1563 ms 1528 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1553 ms 2680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1579 ms 3704 KB Time limit exceeded
2 Halted 0 ms 0 KB -