QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137371 | #2356. Partition of Queries | silly_1_2_3# | WA | 1ms | 3636kb | C++11 | 1.2kb | 2023-08-10 11:29:13 | 2023-08-10 11:29:43 |
Judging History
answer
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),i##z=(b);i<=i##z;i++)
#define ROF(i,a,b) for(int i=(a),i##z=(b);i>=i##z;i--)
#define REP(i,u) for(int i=hd[u],v;v=to[i],i;i=nxt[i])
#define temT template<typename T>
#define temT12 template<typename T1,typename T2>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
const int N=int(1e5)+10;
ll f0[N],pa[N],pq[N],f[N]; char a[N]; int n,y;
bool check(int j,int i){
int tmp=f0[i]+y+f[j]+pa[j]*pq[j]-pa[j]*pq[i];
if(f[i]>tmp) return f[i]=tmp,true;
else return false;
}
int main(){
cin>>n>>y; FOR(i,1,n) while(a[i]!='+' && a[i]!='?') cin>>a[i];
FOR(i,1,n) pa[i]=pa[i-1]+(a[i]=='+');
FOR(i,1,n) pq[i]=pq[i-1]+(a[i]=='?');
FOR(i,1,n) f0[i]=f0[i-1]+(a[i]=='?'?pa[i]:0);
/*
FOR(i,1,n){
f[i]=f0[i];
FOR(j,0,i-1) f[i]=min(f[i],f0[i]+y+f[j]+pa[j]*pq[j]-pa[j]*pq[i]);
}
*/
FOR(i,1,n) f[i]=f0[i];
int l=1,r,lp;
FOR(i,0,n-1){
if(i==l) l++; r=n;
int mid,pos=-1;
while(l<=r){
mid=(l+r)/2;
if(check(i,mid))
pos=mid,r=mid-1;
else
l=mid+1;
}
if(pos!=-1){
FOR(j,lp,pos-1) if(i>0) check(i-1,j);
lp=l=pos;
}else{ l=lp; }
}
cout<<f[n];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3636kb
input:
6 5 ++??+?
output:
7
result:
wrong answer 1st lines differ - expected: '6', found: '7'