QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#170921#5474. Incredibly Cute Penguin ChicksPhantomThreshold#WA 547ms87056kbC++202.3kb2023-09-09 16:12:142023-09-09 16:13:39

Judging History

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

  • [2023-09-09 16:13:39]
  • 评测
  • 测评结果:WA
  • 用时:547ms
  • 内存:87056kb
  • [2023-09-09 16:12:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MOD=998244353,L=-1e6,R=1e6;
const int maxp=77777777;
int lson[maxp],rson[maxp];
int sum[maxp];
int top=0;
void upd(int cur)
{
	cur[sum]=(cur[lson][sum]+cur[rson][sum])%MOD;
}
/*
int build(int l,int r)
{
	int ret=++top;
	ret[sum]=0;
	if(l!=r)
	{
		int mid=l+(r-l)/2;
		ret[lson]=build(l,mid);
		ret[rson]=build(mid+1,r);
	}
	return ret;
}
*/
void change(int &cur,int l,int r,int pos,int del)
{
	if(not cur)
	{
		cur=++top;
	}
	cur[sum]=(cur[sum]+del)%MOD;
	if(l==r)return;
	int mid=l+(r-l)/2;
	if(pos<=mid)change(cur[lson],l,mid,pos,del);
	else change(cur[rson],mid+1,r,pos,del);
}
int query(int &cur,int l,int r,int pos)//query <=pos
{
//	cerr<<"query "<<l<<' '<<r<<' '<<pos<<endl;
	if(not cur)return 0;
	if(l>pos)return 0;
	if(r<=pos)return cur[sum];
	int mid=l+(r-l)/2;
	return query(cur[lson],l,mid,pos)+query(cur[rson],mid+1,r,pos);
}
//#define sum wadihwifh
int main()
{
	string s;
	cin>>s;
	int n=s.length();
	vector<vector<int>> pre(n+5,vector<int>(3));
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
			pre[i][j]=pre[i-1][j];
		if(s[i-1]=='I')
			pre[i][0]++;
		else if(s[i-1]=='C')
			pre[i][1]++;
		else
			pre[i][2]++;
	}
	map<int,int> X,Y,Z;
	auto upd=[&](int x,int y,int z,int val)
	{
//		cerr<<"upd "<<x<<' '<<y<<' '<<z<<' '<<val<<endl;
//		cerr<<"changeX "<<y-z<<' '<<x-z<<' '<<val<<endl;
		change(X[y-z],L,R,x-z,val);
//		cerr<<"changeY "<<z-x<<' '<<y-x<<' '<<val<<endl;
		change(Y[z-x],L,R,y-x,val);
//		cerr<<"changeZ "<<x-y<<' '<<z-y<<' '<<val<<endl;
		change(Z[x-y],L,R,z-y,val);
	};
	auto cal=[&](int x,int y,int z)
	{
//		cerr<<"cal "<<x<<' '<<y<<' '<<z<<endl;
		long long ret=0;
//		cerr<<"queryX "<<y-z<<' '<<x-z<<' '<<query(X[y-z],L,R,x-z-1)<<endl;
		ret+=query(X[y-z],L,R,x-z-1);
//		cerr<<"queryY "<<z-x<<' '<<y-x<<' '<<query(Y[z-x],L,R,y-x-1)<<endl;
		ret+=query(Y[z-x],L,R,y-x-1);
//		cerr<<"queryZ "<<x-y<<' '<<z-y<<' '<<query(Z[x-y],L,R,z-y-1)<<endl;
		ret+=query(Z[x-y],L,R,z-y-1);
		return ret%MOD;
	};
	vector<long long> dp(n+5);
	dp[0]=1;
	upd(pre[0][0],pre[0][1],pre[0][2],dp[0]);
	for(int i=1;i<=n;i++)
	{
		dp[i]=cal(pre[i][0],pre[i][1],pre[i][2]);
		upd(pre[i][0],pre[i][1],pre[i][2],dp[i]);
//		cerr<<i<<' '<<dp[i]<<endl;
	}
	cout<<dp[n]<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3432kb

input:

ICPC

output:

2

result:

ok single line: '2'

Test #2:

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

input:

CCCIIIPPP

output:

69

result:

ok single line: '69'

Test #3:

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

input:

PICCICCIPPI

output:

24

result:

ok single line: '24'

Test #4:

score: -100
Wrong Answer
time: 547ms
memory: 87056kb

input:

PCPPCCICPICPCPCPCCPPIPPPIICCCICPICCPPPIPCCCCICCIICPCCICCCPCICIPPIPIPIPPCCPCIPPCCPPCCIPPPIPPCIICIIIPPCIPPICPPICCPIICCCCCCCICPCCPPIPIPICPCIICPCCIPICCCPPCPIIICPCPPPIIIIICCCPCICCPPCPPCICIIIPIPICPCPPPPICPCPIPIIICCICPCIPPICCICPIIPPCCCIICPCPCCICCPICPPPPPPICCCIPCCICICIPICIIICCICPCIPIICPIPIIICCPCCIIPCCCCPIPI...

output:

523690641

result:

wrong answer 1st lines differ - expected: '216523282', found: '523690641'