QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#290244#5822. 城市建设50lty1220 1ms3860kbC++14646b2023-12-24 16:33:472023-12-24 16:33:47

Judging History

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

  • [2023-12-24 16:33:47]
  • 评测
  • 测评结果:20
  • 用时:1ms
  • 内存:3860kb
  • [2023-12-24 16:33:47]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int n,c,ans=1e18;
int f[N],b[N];
void dfs(int k,int cnt){
	if(cnt*c>=ans) return;
	if(k>n){
		int w=0,s=cnt*c;
		for(int i=1; i<=n; i++){
			if(f[i]) b[++w]=i;
		}
		for(int i=2; i<=w; i++) s+=b[i]-b[i-1];
		for(int i=1; i<=n; i++){
			if(!f[i]){
				int ss=1e9;
				for(int j=1; j<=w; j++) ss=min(ss,abs(b[j]-i));
				s+=ss; 
			}
		} 
		ans=min(ans,s);
		return;
	}
	dfs(k+1,cnt);
	f[k]=1;
	dfs(k+1,cnt+1);
	f[k]=0;
}
signed main(){
	scanf("%lld%lld",&n,&c);
	dfs(1,0);
	printf("%lld\n",ans);
	return 0;
}
/*
6 3

12
*/

详细

Test #1:

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

input:

14
7

output:

45

result:

ok single line: '45'

Test #2:

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

input:

15
9

output:

53

result:

ok single line: '53'

Test #3:

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

input:

15
32

output:

88

result:

ok single line: '88'

Test #4:

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

input:

18
47

output:

128

result:

ok single line: '128'

Test #5:

score: 0
Time Limit Exceeded

input:

691
13

output:


result:


Test #6:

score: 0
Time Limit Exceeded

input:

723
381

output:


result:


Test #7:

score: 0
Time Limit Exceeded

input:

530
4577

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

873
71661

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

50512
6380

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

94371
8943

output:


result:


Test #11:

score: 0
Time Limit Exceeded

input:

51969
2391

output:


result:


Test #12:

score: 0
Time Limit Exceeded

input:

90967
8394

output:


result:


Test #13:

score: 0
Memory Limit Exceeded

input:

903367404
61

output:


result:


Test #14:

score: 0
Memory Limit Exceeded

input:

619459664
4190

output:


result:


Test #15:

score: 0
Memory Limit Exceeded

input:

714829312
304390

output:


result:


Test #16:

score: 0
Memory Limit Exceeded

input:

760183494
45248537

output:


result:


Test #17:

score: 0
Memory Limit Exceeded

input:

500350887
499

output:


result:


Test #18:

score: 0
Memory Limit Exceeded

input:

837064072
96455

output:


result:


Test #19:

score: 0
Memory Limit Exceeded

input:

784256648
6177252

output:


result:


Test #20:

score: 0
Memory Limit Exceeded

input:

650371022
480071734

output:


result: