QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#290782#5822. 城市建设Nwayy25 3ms3728kbC++14835b2023-12-25 13:53:422023-12-25 13:53:44

Judging History

你现在查看的是最新测评结果

  • [2023-12-25 13:53:44]
  • 评测
  • 测评结果:25
  • 用时:3ms
  • 内存:3728kb
  • [2023-12-25 13:53:42]
  • 提交

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];
signed main(){
	scanf("%lld%lld",&n,&c);
	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++;
		}
		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];
		}
		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: 5
Accepted
time: 1ms
memory: 3640kb

input:

14
7

output:

45

result:

ok single line: '45'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3604kb

input:

15
9

output:

53

result:

ok single line: '53'

Test #3:

score: 5
Accepted
time: 1ms
memory: 3584kb

input:

15
32

output:

88

result:

ok single line: '88'

Test #4:

score: 5
Accepted
time: 1ms
memory: 3728kb

input:

18
47

output:

128

result:

ok single line: '128'

Test #5:

score: 0
Wrong Answer
time: 2ms
memory: 3652kb

input:

691
13

output:

22252

result:

wrong answer 1st lines differ - expected: '3152', found: '22252'

Test #6:

score: 0
Wrong Answer
time: 2ms
memory: 3636kb

input:

723
381

output:

26946

result:

wrong answer 1st lines differ - expected: '14800', found: '26946'

Test #7:

score: 0
Wrong Answer
time: 1ms
memory: 3712kb

input:

530
4577

output:

37185

result:

wrong answer 1st lines differ - expected: '36261', found: '37185'

Test #8:

score: 5
Accepted
time: 3ms
memory: 3588kb

input:

873
71661

output:

239024

result:

ok single line: '239024'

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

output:


result: