QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#290786 | #5822. 城市建设 | Nwayy | 0 | 1ms | 3896kb | C++14 | 975b | 2023-12-25 13:59:34 | 2023-12-25 13:59:34 |
answer
#include<bits/stdc++.h>
using namespace std;
#define N 1005
#define int long long
int n,m,i,j,ans=1e18,c,u[N],s[N],h,lts[N],f[N];
signed main(){
scanf("%lld%lld",&n,&c);
for(i=1;i<=n;i++) f[i]=i;
for(i=1;i<=n;i++){
int k=n/i,p=0,sum=0,g=0;//12/8
k=max(k,2ll),h=1;
memset(u,0,sizeof(u));
// for(j=k/2+1;j<=n;j+=k) u[j]=1,p++;
// j=1,m=0;
// while(p<i){
// if(u[j]==0) u[j]=1,p++;
// j++;
// }
random_shuffle(f+1,f+1+n);
for(j=1;j<=i;j++) u[f[j]]=1;
for(j=1;j<=n;j++){
if(u[j]==1) s[++m]=j;
}
s[0]=-1e18,s[m+1]=1e18;
for(j=1;j<=m;j++){
sum+=(j-1)*s[j]-g;
g+=s[j];
}
for(j=1;j<=n;j++){
if(j>s[h]) h++;
if(j-s[h-1]<s[h]-j) lts[j]=s[h-1];
else lts[j]=s[h];
}//printf("AAA %lld\n",i);
sum+=i*c;
for(j=1;j<=n;j++) sum+=abs(lts[j]-j);
ans=min(ans,sum);
// for(j=1;j<=n;j++) printf("%lld ",lts[j]);
// printf("%lld\n",sum);
// 2 4 7
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3880kb
input:
14 7
output:
56
result:
wrong answer 1st lines differ - expected: '45', found: '56'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3896kb
input:
15 9
output:
74
result:
wrong answer 1st lines differ - expected: '53', found: '74'
Test #3:
score: 0
Wrong Answer
time: 1ms
memory: 3644kb
input:
15 32
output:
97
result:
wrong answer 1st lines differ - expected: '88', found: '97'
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 3656kb
input:
18 47
output:
148
result:
wrong answer 1st lines differ - expected: '128', found: '148'
Test #5:
score: 0
Runtime Error
input:
691 13
output:
result:
Test #6:
score: 0
Runtime Error
input:
723 381
output:
result:
Test #7:
score: 0
Runtime Error
input:
530 4577
output:
result:
Test #8:
score: 0
Runtime Error
input:
873 71661
output:
result:
Test #9:
score: 0
Runtime Error
input:
50512 6380
output:
result:
Test #10:
score: 0
Runtime Error
input:
94371 8943
output:
result:
Test #11:
score: 0
Runtime Error
input:
51969 2391
output:
result:
Test #12:
score: 0
Runtime Error
input:
90967 8394
output:
result:
Test #13:
score: 0
Runtime Error
input:
903367404 61
output:
result:
Test #14:
score: 0
Runtime Error
input:
619459664 4190
output:
result:
Test #15:
score: 0
Runtime Error
input:
714829312 304390
output:
result:
Test #16:
score: 0
Runtime Error
input:
760183494 45248537
output:
result:
Test #17:
score: 0
Runtime Error
input:
500350887 499
output:
result:
Test #18:
score: 0
Runtime Error
input:
837064072 96455
output:
result:
Test #19:
score: 0
Runtime Error
input:
784256648 6177252
output:
result:
Test #20:
score: 0
Runtime Error
input:
650371022 480071734