QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137374 | #2356. Partition of Queries | Rd_rainydays# | WA | 3ms | 14076kb | C++20 | 1.1kb | 2023-08-10 11:34:37 | 2023-08-10 11:34:41 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
#define N 2000005
using namespace std;
ll res[N],cnt[N],sum[N],dp[N];
int n;
ll y;
ll pty[N],ptx[N];
int q[N],fr,ed;
// double slope(int i,int r){
// }
char s[N];
ll final_ans=0;
int main(){
scanf("%d%lld",&n,&y);
scanf("%s",s+1);
for(int i=1;i<=n;i++){
sum[i]=sum[i-1];
cnt[i]=cnt[i-1];
res[i]=res[i-1];
if(s[i]=='?'){
sum[i]++;
res[i]+=cnt[i];
}
else cnt[i]++;
}
final_ans=res[n];
fr=1,ed=0;
q[++ed]=1;
ptx[1]=pty[1]=0;
for(int i=2;i<=n;i++){
if(s[i]=='+')continue;
while(fr<ed&&pty[q[fr+1]]-pty[q[fr]]<=sum[i-1]*(ptx[q[fr+1]]-ptx[q[fr]]))fr++;
dp[i]=dp[q[fr]]+y+res[i-1]-res[q[fr]-1]-(sum[i-1]-sum[q[fr]-1])*cnt[q[fr]-1];
ptx[i]=cnt[i-1];
pty[i]=dp[i]-res[i-1]+sum[i-1]*cnt[i-1];
final_ans=min(final_ans,dp[i]+res[n]-res[i-1]-(sum[n]-sum[i-1])*cnt[i-1]);
while(fr<ed&&(pty[q[ed]]-pty[q[ed-1]])*(ptx[i]-ptx[q[ed-1]])>(pty[i]-pty[q[ed-1]])*(ptx[q[ed]]-ptx[q[ed-1]]))ed--;
q[++ed]=i;
}
printf("%lld\n",final_ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 11840kb
input:
6 5 ++??+?
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 1ms
memory: 11868kb
input:
6 8 ++??+?
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 3ms
memory: 12080kb
input:
5 1 +++++
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 11820kb
input:
10 0 ++?+??++??
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 2ms
memory: 11844kb
input:
12 100 +?+++??+??++
output:
19
result:
ok single line: '19'
Test #6:
score: 0
Accepted
time: 1ms
memory: 11844kb
input:
1 1 ?
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 2ms
memory: 12080kb
input:
9 7 ++++++++?
output:
7
result:
ok single line: '7'
Test #8:
score: 0
Accepted
time: 2ms
memory: 11800kb
input:
9 8 ++++++++?
output:
8
result:
ok single line: '8'
Test #9:
score: 0
Accepted
time: 2ms
memory: 11852kb
input:
10 15 ++++++++??
output:
15
result:
ok single line: '15'
Test #10:
score: 0
Accepted
time: 0ms
memory: 11908kb
input:
5 3 +?+?+
output:
3
result:
ok single line: '3'
Test #11:
score: 0
Accepted
time: 2ms
memory: 12092kb
input:
10 5 +?+?+??+??
output:
10
result:
ok single line: '10'
Test #12:
score: 0
Accepted
time: 1ms
memory: 11944kb
input:
10 7 +?+?+??+??
output:
12
result:
ok single line: '12'
Test #13:
score: 0
Accepted
time: 0ms
memory: 11940kb
input:
15 4 +?+?+??+??+??+?
output:
14
result:
ok single line: '14'
Test #14:
score: 0
Accepted
time: 3ms
memory: 11848kb
input:
15 6 +?+?+??+??+??+?
output:
18
result:
ok single line: '18'
Test #15:
score: 0
Accepted
time: 2ms
memory: 12044kb
input:
19 8 +?+?+??+??+??+?++??
output:
28
result:
ok single line: '28'
Test #16:
score: 0
Accepted
time: 1ms
memory: 11908kb
input:
20 9 +?+?+??+??+??+?++???
output:
30
result:
ok single line: '30'
Test #17:
score: 0
Accepted
time: 0ms
memory: 11832kb
input:
500 100 +?+?+??+??+??+?++?????++??+?+????????????+++?+?+???++?+?+++++++????++??+??+++??++++?++??+??+??+?????++++???+??++?+?++?++???++++???????+??????????++?+??+?+++???+?+???++?++?++++???++?++?????+??????+?++???++??+?++?+??+??++??++??++?+?+?+++??+??++????+?++?++?++??+?+++?+?+???+?+++?++?++++?????++++...
output:
2710
result:
ok single line: '2710'
Test #18:
score: -100
Wrong Answer
time: 3ms
memory: 14076kb
input:
10000 100 +?+?+??+??+??+?++?????++??+?+????????????+++?+?+???++?+?+++++++????++??+??+++??++++?++??+??+??+?????++++???+??++?+?++?++???++++???????+??????????++?+??+?+++???+?+???++?++?++++???++?++?????+??????+?++???++??+?++?+??+??++??++??++?+?+?+++??+??++????+?++?++?++??+?+++?+?+???+?+++?++?++++?????++...
output:
2451419
result:
wrong answer 1st lines differ - expected: '56616', found: '2451419'