QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#28201#2356. Partition of QueriesWu_RenTL 14ms12044kbC++17570b2022-04-12 19:27:092022-04-29 09:15:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 09:15:21]
  • 评测
  • 测评结果:TL
  • 用时:14ms
  • 内存:12044kb
  • [2022-04-12 19:27:09]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n,m,y,suf[1000010],a[1000010];
ll f[1000010],sufi[1000010];
char s[1000010];
int main(){
	scanf("%d%d%s",&n,&y,s+1);
	for(int i=1,j=0;i<=n;i++){
		if(s[i]=='?') a[++m]=j,j=0;
		else j++;
	}
	a[++m]=0;
	n=m;
	for(int i=n;i>=1;i--){
		suf[i]=suf[i+1]+a[i];
		sufi[i]=sufi[i+1]+a[i]*(n-i+1ll); 
	}
	f[0]=0;
	for(int i=1;i<=n;i++){
		f[i]=1e18;
		for(int j=1;j<=i;j++) f[i]=min(f[i],f[j-1]+sufi[j]+1ll*(i-1-n)*suf[j]-(i-1-n)*suf[i+1]-sufi[i+1]+y);
	}
	printf("%lld\n",f[n]-y);
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 9944kb

input:

6 5
++??+?

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 1ms
memory: 9932kb

input:

6 8
++??+?

output:

7

result:

ok single line: '7'

Test #3:

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

input:

5 1
+++++

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 2ms
memory: 12044kb

input:

10 0
++?+??++??

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 1ms
memory: 11904kb

input:

12 100
+?+++??+??++

output:

19

result:

ok single line: '19'

Test #6:

score: 0
Accepted
time: 1ms
memory: 9864kb

input:

1 1
?

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 9928kb

input:

9 7
++++++++?

output:

7

result:

ok single line: '7'

Test #8:

score: 0
Accepted
time: 0ms
memory: 9948kb

input:

9 8
++++++++?

output:

8

result:

ok single line: '8'

Test #9:

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

input:

10 15
++++++++??

output:

15

result:

ok single line: '15'

Test #10:

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

input:

5 3
+?+?+

output:

3

result:

ok single line: '3'

Test #11:

score: 0
Accepted
time: 2ms
memory: 9940kb

input:

10 5
+?+?+??+??

output:

10

result:

ok single line: '10'

Test #12:

score: 0
Accepted
time: 2ms
memory: 11968kb

input:

10 7
+?+?+??+??

output:

12

result:

ok single line: '12'

Test #13:

score: 0
Accepted
time: 4ms
memory: 9932kb

input:

15 4
+?+?+??+??+??+?

output:

14

result:

ok single line: '14'

Test #14:

score: 0
Accepted
time: 2ms
memory: 11924kb

input:

15 6
+?+?+??+??+??+?

output:

18

result:

ok single line: '18'

Test #15:

score: 0
Accepted
time: 2ms
memory: 11992kb

input:

19 8
+?+?+??+??+??+?++??

output:

28

result:

ok single line: '28'

Test #16:

score: 0
Accepted
time: 1ms
memory: 9940kb

input:

20 9
+?+?+??+??+??+?++???

output:

30

result:

ok single line: '30'

Test #17:

score: 0
Accepted
time: 2ms
memory: 9928kb

input:

500 100
+?+?+??+??+??+?++?????++??+?+????????????+++?+?+???++?+?+++++++????++??+??+++??++++?++??+??+??+?????++++???+??++?+?++?++???++++???????+??????????++?+??+?+++???+?+???++?++?++++???++?++?????+??????+?++???++??+?++?+??+??++??++??++?+?+?+++??+??++????+?++?++?++??+?+++?+?+???+?+++?++?++++?????++++...

output:

2710

result:

ok single line: '2710'

Test #18:

score: 0
Accepted
time: 14ms
memory: 12000kb

input:

10000 100
+?+?+??+??+??+?++?????++??+?+????????????+++?+?+???++?+?+++++++????++??+??+++??++++?++??+??+??+?????++++???+??++?+?++?++???++++???????+??????????++?+??+?+++???+?+???++?++?++++???++?++?????+??????+?++???++??+?++?+??+??++??++??++?+?+?+++??+??++????+?++?++?++??+?+++?+?+???+?+++?++?++++?????++...

output:

56616

result:

ok single line: '56616'

Test #19:

score: -100
Time Limit Exceeded

input:

500000 3000
+?+?+??+??+??+?++?????++??+?+????????????+++?+?+???++?+?+++++++????++??+??+++??++++?++??+??+??+?????++++???+??++?+?++?++???++++???????+??????????++?+??+?+++???+?+???++?++?++++???++?++?????+??????+?++???++??+?++?+??+??++??++??++?+?+?+++??+??++????+?++?++?++??+?+++?+?+???+?+++?++?++++?????...

output:


result: