QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#291348#5822. 城市建设Nwayy30 2ms3940kbC++14862b2023-12-26 12:43:412023-12-26 12:43:42

Judging History

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

  • [2023-12-26 12:43:42]
  • 评测
  • 测评结果:30
  • 用时:2ms
  • 内存:3940kb
  • [2023-12-26 12:43:41]
  • 提交

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=2;j<=m;j++) sum+=s[j]-s[j-1];
		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;
}

/*
0 0 1 0 0 1

6+3+2+1+1+1

1 2 3 10
*/ 

详细

Test #1:

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

input:

14
7

output:

45

result:

ok single line: '45'

Test #2:

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

input:

15
9

output:

53

result:

ok single line: '53'

Test #3:

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

input:

15
32

output:

88

result:

ok single line: '88'

Test #4:

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

input:

18
47

output:

128

result:

ok single line: '128'

Test #5:

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

input:

691
13

output:

3000

result:

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

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 3876kb

input:

723
381

output:

14801

result:

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

Test #7:

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

input:

530
4577

output:

36261

result:

ok single line: '36261'

Test #8:

score: 5
Accepted
time: 2ms
memory: 3812kb

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: