結果

問題 No.1677 mæx
ユーザー kotatsugamekotatsugame
提出日時 2021-09-10 21:43:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 542 ms
コンパイル使用メモリ 70,116 KB
実行使用メモリ 7,044 KB
最終ジャッジ日時 2023-09-02 16:35:57
合計ジャッジ時間 1,629 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 8 ms
5,932 KB
testcase_05 AC 8 ms
5,992 KB
testcase_06 AC 8 ms
5,880 KB
testcase_07 AC 8 ms
5,972 KB
testcase_08 AC 8 ms
5,936 KB
testcase_09 AC 8 ms
5,872 KB
testcase_10 AC 8 ms
5,944 KB
testcase_11 AC 8 ms
5,968 KB
testcase_12 AC 8 ms
5,836 KB
testcase_13 AC 8 ms
6,044 KB
testcase_14 AC 8 ms
5,960 KB
testcase_15 AC 8 ms
5,900 KB
testcase_16 AC 8 ms
5,868 KB
testcase_17 AC 9 ms
5,840 KB
testcase_18 AC 8 ms
5,956 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 9 ms
7,044 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:55:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-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