QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#137376#2356. Partition of Queriessilly_1_2_3#WA 1ms3632kbC++111.2kb2023-08-10 11:36:312023-08-10 11:36:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 11:36:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3632kb
  • [2023-08-10 11:36:31]
  • 提交

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;
const ll linf=ll(1e17)+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++,lp++; 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: 100
Accepted
time: 0ms
memory: 3432kb

input:

6 5
++??+?

output:

6

result:

ok single line: '6'

Test #2:

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

input:

6 8
++??+?

output:

7

result:

ok single line: '7'

Test #3:

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

input:

5 1
+++++

output:

0

result:

ok single line: '0'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3580kb

input:

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

output:

6

result:

wrong answer 1st lines differ - expected: '0', found: '6'