QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137371#2356. Partition of Queriessilly_1_2_3#WA 1ms3636kbC++111.2kb2023-08-10 11:29:132023-08-10 11:29:43

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:29:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3636kb
  • [2023-08-10 11:29:13]
  • 提交

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;
}

詳細信息

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'