QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#28218#2356. Partition of QueriesWu_RenWA 8ms26800kbC++17795b2022-04-12 20:20:032022-04-29 09:17:03

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:17:03]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:26800kb
  • [2022-04-12 20:20:03]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n,m,y,suf[1000010],a[1000010],l,r,q[1000010];
ll f[1000010],sufi[1000010],X[1000010],Y[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;
	l=1,r=0;
	for(int i=1;i<=n;i++){
		f[i]=1e18;
		Y[i]=f[i-1]+sufi[i]-(1ll+n)*suf[i],X[i]=-suf[i];
		while(l<r&&(X[q[r-1]]-X[i])*(Y[q[r]]-Y[i])-(Y[q[r-1]]-Y[i])*(X[q[r]]-X[i])<=0) r--;
		q[++r]=i;
		while(l<r&&(Y[q[l+1]]-Y[q[l]])<=i*(X[q[l+1]]-X[q[l]])) l++;
		f[i]=Y[q[l]]-i*X[q[l]];
		f[i]+=y-(i-1-n)*suf[i+1]-sufi[i+1];
	}
	printf("%lld\n",f[n]-y);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 18052kb

input:

6 5
++??+?

output:

6

result:

ok single line: '6'

Test #2:

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

input:

6 8
++??+?

output:

7

result:

ok single line: '7'

Test #3:

score: 0
Accepted
time: 3ms
memory: 16140kb

input:

5 1
+++++

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 6ms
memory: 16140kb

input:

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

output:

0

result:

ok single line: '0'

Test #5:

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

input:

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

output:

19

result:

ok single line: '19'

Test #6:

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

input:

1 1
?

output:

0

result:

ok single line: '0'

Test #7:

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

input:

9 7
++++++++?

output:

7

result:

ok single line: '7'

Test #8:

score: 0
Accepted
time: 6ms
memory: 16024kb

input:

9 8
++++++++?

output:

8

result:

ok single line: '8'

Test #9:

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

input:

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

output:

15

result:

ok single line: '15'

Test #10:

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

input:

5 3
+?+?+

output:

3

result:

ok single line: '3'

Test #11:

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

input:

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

output:

10

result:

ok single line: '10'

Test #12:

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

input:

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

output:

12

result:

ok single line: '12'

Test #13:

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

input:

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

output:

14

result:

ok single line: '14'

Test #14:

score: 0
Accepted
time: 3ms
memory: 18116kb

input:

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

output:

18

result:

ok single line: '18'

Test #15:

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

input:

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

output:

28

result:

ok single line: '28'

Test #16:

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

input:

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

output:

30

result:

ok single line: '30'

Test #17:

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

input:

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

output:

2710

result:

ok single line: '2710'

Test #18:

score: 0
Accepted
time: 3ms
memory: 16128kb

input:

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

output:

56616

result:

ok single line: '56616'

Test #19:

score: -100
Wrong Answer
time: 8ms
memory: 26800kb

input:

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

output:

-5190304154383913

result:

wrong answer 1st lines differ - expected: '17820759', found: '-5190304154383913'