QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#22325 | #2356. Partition of Queries | DaBenZhongXiaSongKuaiDi# | WA | 4ms | 7840kb | C++20 | 977b | 2022-03-09 15:28:31 | 2022-04-30 00:54:04 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1000005;
int n;
ll y;
int a[N],tot=0;
ll f[N],ans=100000000000000ll;
int q[N],nowl=1,nowr=0;
double Slope(int i,int j){
ll x1=f[i]+(ll)a[i]*n-f[j]-(ll)a[j]*n;
ll x2=a[i]-a[j];
return (double)x1/x2;
}
int main(){
scanf("%d %lld\n",&n,&y);
int lst=0;
for(int i=1;i<=n;i++){
char x;
scanf("%c",&x);
//cout<<i<<" "<<x<<endl;
if(x=='?') a[++tot]=(i-lst-1),lst=i;
}
for(int i=1;i<=tot;i++) a[i]+=a[i-1];
for(int i=1;i<=tot;i++) f[0]+=a[i];
ans=min(ans,f[0]);//for(int i=1;i<=tot;i++) cout<<a[i]<<" ";cout<<endl;
q[++nowr]=0;
for(int i=1;i<=tot;i++){
while(nowl<nowr && Slope(q[nowl],q[nowl+1])<i) nowl++;
int p=q[nowl];
f[i]=f[p]+y-(ll)(a[i]-a[p])*(tot-i+1);ans=min(ans,f[i]);
//cout<<i<<" zhuan: "<<p<<" "<<f[i]<<endl;
while(nowl<nowr && Slope(q[nowr-1],q[nowr])>Slope(q[nowr],i)) nowr--;
q[++nowr]=i;
}
cout<<ans<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 7820kb
input:
6 5 ++??+?
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 4ms
memory: 7840kb
input:
6 8 ++??+?
output:
7
result:
ok single line: '7'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
5 1 +++++
output:
0
result:
ok single line: '0'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 7724kb
input:
10 0 ++?+??++??
output:
6
result:
wrong answer 1st lines differ - expected: '0', found: '6'