QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#103955#5822. 城市建设sichengzhou100 ✓2ms3772kbC++14555b2023-05-07 23:25:442023-05-07 23:25:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-07 23:25:47]
  • 评测
  • 测评结果:100
  • 用时:2ms
  • 内存:3772kb
  • [2023-05-07 23:25:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e3+3;
int n,c;
LL f(int m)
{
	int d=(n-m)/(2*m),rm=(n-m)%(2*m);
	LL ret=(LL)2*m*d*(d+1)/2+(LL)(2*d+1)*(m-1)+(LL)m*c;
	if(rm<2)
	{
		return ret+(LL)rm*(d+1);
	}else{
		return ret+(LL)rm*(d+1)+(LL)(rm-2);
	}
}
int main()
{
	scanf("%d%d",&n,&c);
	if(n==1)
	{
		printf("0\n");
		return 0; 
	}
	int L=1,R=n;
	while(L<R)
	{
		int mid=(L+R)>>1;
		if(f(mid)<f(mid+1))
		{
			R=mid;
		}else{
			L=mid+1;
		}
	}
	printf("%lld\n",f(L));
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

14
7

output:

45

result:

ok single line: '45'

Test #2:

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

input:

15
9

output:

53

result:

ok single line: '53'

Test #3:

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

input:

15
32

output:

88

result:

ok single line: '88'

Test #4:

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

input:

18
47

output:

128

result:

ok single line: '128'

Test #5:

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

input:

691
13

output:

3152

result:

ok single line: '3152'

Test #6:

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

input:

723
381

output:

14800

result:

ok single line: '14800'

Test #7:

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

input:

530
4577

output:

36261

result:

ok single line: '36261'

Test #8:

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

input:

873
71661

output:

239024

result:

ok single line: '239024'

Test #9:

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

input:

50512
6380

output:

4084971

result:

ok single line: '4084971'

Test #10:

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

input:

94371
8943

output:

9018507

result:

ok single line: '9018507'

Test #11:

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

input:

51969
2391

output:

2593001

result:

ok single line: '2593001'

Test #12:

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

input:

90967
8394

output:

8424956

result:

ok single line: '8424956'

Test #13:

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

input:

903367404
61

output:

7949633140

result:

ok single line: '7949633140'

Test #14:

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

input:

619459664
4190

output:

40716267253

result:

ok single line: '40716267253'

Test #15:

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

input:

714829312
304390

output:

395097112253

result:

ok single line: '395097112253'

Test #16:

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

input:

760183494
45248537

output:

5114288962225

result:

ok single line: '5114288962225'

Test #17:

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

input:

500350887
499

output:

11674853991

result:

ok single line: '11674853991'

Test #18:

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

input:

837064072
96455

output:

260805440727

result:

ok single line: '260805440727'

Test #19:

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

input:

784256648
6177252

output:

1949981815499

result:

ok single line: '1949981815499'

Test #20:

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

input:

650371022
480071734

output:

14250630194974

result:

ok single line: '14250630194974'

Extra Test:

score: 0
Extra Test Passed