# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
646716 |
2022-09-30T12:36:32 Z |
inksamurai |
Krov (COCI17_krov) |
C++17 |
|
1500 ms |
2008 KB |
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3SJjfN1 ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
signed main(){
_3SJjfN1;
int n;
cin>>n;
vi a(n);
rep(i,n){
cin>>a[i];
}
auto af=[&](int pvt,int x)->int{
int res=0;
per(i,pvt+1){
int need=x-(pvt-i);
res+=abs(need-a[i]);
}
rng(i,pvt+1,n){
int need=x-(i-pvt);
res+=abs(need-a[i]);
}
return res;
};
const int inf=1e18;
int ans=inf;
rep(i,n){
int l=max(i+1,n-i),r=1e10;
while(r-l>3){
int ml=(2*l+r)/3;
int mr=(l+2*r)/3;
int fl=af(i,ml);
int fr=af(i,mr);
if(fl<fr){
r=mr;
}else{
l=ml;
}
}
rng(j,l,r+1){
ans=min(ans,af(i,j));
}
}
print(ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
316 KB |
Output is correct |
2 |
Correct |
122 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
324 KB |
Output is correct |
2 |
Correct |
119 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
320 KB |
Output is correct |
2 |
Correct |
268 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
420 ms |
344 KB |
Output is correct |
2 |
Correct |
483 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
861 ms |
340 KB |
Output is correct |
2 |
Correct |
612 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1573 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1587 ms |
596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1576 ms |
852 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1565 ms |
1520 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1573 ms |
2008 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |