QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#654289 | #7501. Simple Game | ucup-team5071# | WA | 0ms | 3832kb | C++20 | 1.2kb | 2024-10-18 21:21:59 | 2024-10-18 21:22:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
void Solve(){
int n;
cin>>n;
vector<int> a(n+1),s(n+1),f(n+1);
a[0]=1;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a.begin()+1,a.end());
for(int i=1;i<=n;i++)
s[i]=s[i-1]+a[i];
int m=min(n,a[n]),ans=1e18;
int s1=0;
for(int i=1;i<=n;i++)f[i]=1e18;
a.push_back(a[n]);
for(int i=1;i<=m;i++){
int l,r;
if(a[i-1]>=i||a[i]==a[i-1])l=r=i;
else l=a[i-1],r=min(a[i],i);
for(int j=r;j>=l;j--)
f[j]=min(f[j],f[j-1]+abs(j-a[i]));
for(int j=1;j<=n;j++){
cout<<f[j]<<" ";
}
cout<<endl;
for(int j=l;j<=r;j++){
int res=f[j];
int k=lower_bound(a.begin()+i+1,a.end(),j+1)-a.begin();
res+=(s[n]-s[k-1])-(n-k+1)*(j+1);
//if(i==5)cout<<k<<" "<<f[j]<<" "<<res<<endl;
// cout<<"res="<<res<<endl;
if(res==0)cout<<i<<endl;
if(i==5)cout<<k<<" "<<f[j]<<" "<<res<<endl;
ans=min(ans,res);
}
}
cout<<ans<<"\n";
}
signed main(){
ios::sync_with_stdio(false),cin.tie(0);
Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3832kb
input:
4 2 1 4 2 1 3 1 1 4 5 1 4 4 1 9 4 9 1 0 0 1 7 3 1 4 1 5 9 2 6 5 3 5 8 9 8
output:
0 1000000000000000000 1000000000000000000 1000000000000000000 0 0 1000000000000000000 1000000000000000000 0 0 1 1000000000000000000 0 0 1 1 4 -34
result:
wrong answer 1st numbers differ - expected: '5', found: '0'