列表

详情


NC22427. Immortal … Universe

描述

Time flies fast. Days passed and the game finally ended. Rikka has never drunk with your help, so she is still a reputable Japanese citizen.

The red and white left gracefully. Suddenly, Rikka realized that the white player is LCR rather than any elder --- or LCR is the one. She would never know why she didn't get it. Rikka ran after them, but she lost her way while passing fogs.

Spaceships are making their epic voyages across the sky, row upon row of roads and buildings forming concentric circles, reminding humans of alters or Eight-Diagrams. At the end of the fogs, a holy incredible view shows in front of her. The big round planet soon attracts her --- Earth, the home of humankind, is hanging like a big mooncake. What a lunar metropolis!

Rikka finds herself in front of a stock exchange. A boy, who is gazing at the screen and knocking on the keyboard, catches her eyes.

There are two types of shares. Both are controlled by consortiums, so their trends are established.

Each type of share can be divided into some stages, and the stages will process in order. One type has n stages and the other one has m of them. In each stage, one will gain or lose a unit of money. The boy has only one unit of money at first, and he has to process a stage of an arbitrary type (unless all stages of that type have processed, and if so, the other type will process) every day. After (n + m) days all transactions will end and he will finally get his money.

The poor boy knows nothing to help him to make decisions, so he chooses randomly. However, after countless bankruptcies, he has got a keen intuition: if he only has one unit of money, he will know the results of all available stages. A stage is available if and only if he can choose it immediately. In this case, he will never choose the type which will lead him to lose money unless all available types are so. But if he has at least two units of money, he will ignore any known information and choose randomly because he has chances. He has to process every day, and he cannot exit before all transactions have been completed because he can get cash only after (n + m) days.

He will go bankrupt whenever his money runs out. It happens if he only has one unit of money and every available type (which has at least one stage not processed) can lead him to lose it in the next stage.

Of course, the kind-hearted girl will try her best to help. She finds something strange in the codes she got before. It is a hash value of the files from the consortiums!

Soon after, Rikka gets two strings of lengths n and m respectively. Each string contains three types of characters ``P'', ``V'' and ``?'', which mean that the corresponding stage can lead to loss, gain or unknown, respectively. However, the boy doesn't believe her.

Rikka gets anxious. She wonders, according to her information, how many possible trends will never lead him to bankruptcy, modulo 998244353.

A possible trend can be described by two strings of lengths n and m containing only ``P'' and ``V'', and they can be obtained by changing each ``?'' in Rikka's strings into ``P'' or ``V''. It will never lead to bankruptcy if and only if no matter how he chooses each time, he can never go bankrupt.

输入描述

The first line contains a string s of length , consisting of only ``P'', ``V'' and ``?''.

The second line contains a string t of length , consisting of only ``P'', ``V'' and ``?''.

s and t make up Rikka's information.

输出描述

Output a single integer, the number of possible trends which will never lead the boy to bankruptcy, modulo 998244353.

示例1

输入:

PV
??

输出:

1

示例2

输入:

???
P?P

输出:

3

示例3

输入:

?????
?????

输出:

326

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++11(clang++ 3.9) 解法, 执行用时: 1200ms, 内存消耗: 876K, 提交时间: 2020-03-13 12:50:36

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int mod=998244353;
#define MAXNUM 5555
int dps[2][2][MAXNUM*2],dpt[2][2][MAXNUM*2];
char ss[MAXNUM],st[MAXNUM];
int n,m,type1,type2;
void add(int &a,int b)
{
	a+=b;
	if(a>=mod) a-=mod;
 } 
 #define rep(i,s,t) for(int i=s;i<t;i++)
 void getdp(char s[],int n,int dp[][2][MAXNUM*2],int &type)
 {
 	reverse(s+1,s+1+n);
 	type=1;
 	dp[0][0][n]=1;
 	rep(i,1,n+1)
 	{
 		memset(dp[type],0,sizeof(dps[0]));
 		rep(j,0,2*n+1)
 		{
 			if(s[i]!='P')
 			{
 				rep(k,0,2)
 				add(dp[type][k][j+1],dp[!type][k][j]);
			 }
			 if(s[i]!='V'&&j)
			 {
			 	if(j-1>=n)
			 	add(dp[type][1][n],dp[!type][0][j]);
			 	else add(dp[type][0][j-1],dp[!type][0][j]);
			 	add(dp[type][1][min(n,j-1)],dp[!type][1][j]);
			 }
		 }
		 type=!type;
	 }
 }
 int main()
 {
 	scanf("%s%s",ss+1,st+1);
 	n=strlen(ss+1),m=strlen(st+1);
 	getdp(ss,n,dps,type1),getdp(st,m,dpt,type2);
 	int res=0;
 	rep(i,0,2*n+1)
 	rep(j,0,2*m+1)
 	{
 		if(i+j>n+m)
 		add(res,(dps[!type1][0][i]+dps[!type1][1][i])*1LL*(dpt[!type2][0][j]+dpt[!type2][1][j])%mod);
 		else if(i+j==n+m)
 		add(res,dps[!type1][0][i]*1LL*dpt[!type2][0][j]%mod);
	 }
	 printf("%d\n",res);
 	
 }

上一题