結果

問題 No.1677 mæx
ユーザー kotatsugame
提出日時 2021-09-10 21:43:55
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 619 ms
コンパイル使用メモリ 69,708 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-06-11 23:08:44
合計ジャッジ時間 1,550 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<array>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
using dat=array<mint,3>;
string S;
dat f(int&id)
{
	dat ret;ret[0]=ret[1]=ret[2]=0;
	if(S[id]=='0'||S[id]=='1'||S[id]=='2')
	{
		ret[S[id++]-'0']=1;
		return ret;
	}
	else if(S[id]=='?')
	{
		ret[0]=ret[1]=ret[2]=1;
		id++;
		return ret;
	}
	else//if(S[id]=='m')
	{
		id++;
		bool fa=S[id]!='e';
		bool fe=S[id]!='a';
		id++;
		id++;
		id++;
		dat L=f(id);
		id++;
		dat R=f(id);
		id++;
		if(fa)
		{
			ret[0]+=L[0]*R[0];
			ret[1]+=(L[0]+L[1])*(R[0]+R[1])-L[0]*R[0];
			ret[2]+=(L[0]+L[1]+L[2])*(R[0]+R[1]+R[2])-(L[0]+L[1])*(R[0]+R[1]);
		}
		if(fe)
		{
			ret[1]+=L[0]*R[0];
			ret[2]+=L[0]*R[1];
			ret[1]+=L[0]*R[2];
			ret[2]+=L[1]*R[0];
			ret[0]+=L[1]*R[1];
			ret[0]+=L[1]*R[2];
			ret[1]+=L[2]*R[0];
			ret[0]+=L[2]*R[1];
			ret[0]+=L[2]*R[2];
		}
		return ret;
	}
}
main()
{
	cin>>S;
	int K;cin>>K;
	int id=0;
	dat ans=f(id);
	cout<<ans[K].val()<<endl;
}
0