QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#82555#5576. Advertising ICPCYanagi_OrigamiRE 0ms0kbC++142.9kb2023-02-28 03:42:222023-02-28 03:42:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-28 03:42:24]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-02-28 03:42:22]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cmath>
#define rep(i,a,b) for(int i=a;i<=(b);i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int Mod=998244353;
char s[10][10];
int f[10][10][2][20005],n,m;
int Upd(int &x,int y){ x=(x+y)%Mod; }
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%s",s[i]+1);
	int MAXS=1;
	rep(i,1,m+1) MAXS*=3;
	f[0][m][0][MAXS-1]=1;
	rep(i,1,n){
		rep(S,0,MAXS-1){
			if(f[i-1][m][0][S]==0&&f[i-1][m][1][S]==0) continue;
			//printf("## %d %d at %d\n",f[i-1][m][0][S],f[i-1][m][1][S],i-1);
			if(s[i][1]=='?'){
				rep(k,0,2){
					Upd(f[i][1][0][S*3%MAXS+k],f[i-1][m][0][S]);
					Upd(f[i][1][1][S*3%MAXS+k],f[i-1][m][1][S]);
					//printf("%d -> %d : %d %d %d\n",S,S*3%MAXS+k,f[i][1][0][S*3%MAXS+k],i,1);
				}
			}
			if(s[i][1]=='I'){
				Upd(f[i][1][0][S*3%MAXS+0],f[i-1][m][0][S]);
				Upd(f[i][1][1][S*3%MAXS+0],f[i-1][m][1][S]);
				//printf("%d -> %d\n",S,S*3%MAXS+0);
			}
			if(s[i][1]=='C'){
				Upd(f[i][1][0][S*3%MAXS+1],f[i-1][m][0][S]);
				Upd(f[i][1][1][S*3%MAXS+1],f[i-1][m][1][S]);
				//printf("%d -> %d\n",S,S*3%MAXS+1);
			}
			if(s[i][1]=='P'){
				Upd(f[i][1][0][S*3%MAXS+2],f[i-1][m][0][S]);
				Upd(f[i][1][1][S*3%MAXS+2],f[i-1][m][1][S]);
				//printf("%d -> %d\n",S,S*3%MAXS+2);
			}
		}
		rep(j,2,m){
			rep(S,0,MAXS-1){
				//if(S==0&&i==2&&j==3) printf("#@#@ %d\n",f[i][j-1][0][S]);
				//if(S==0&&f[i][j-1][0][S]!=0) puts("HERE");
				if(f[i][j-1][0][S]==0&&f[i][j-1][1][S]==0) continue;
				if(s[i][j]=='?'){
					rep(k,0,1){
						Upd(f[i][j][0][S*3%MAXS+k*2],f[i][j-1][0][S]);
						Upd(f[i][j][1][S*3%MAXS+k*2],f[i][j-1][1][S]);
						//printf("sec %d -> %d\n",S,S*3%MAXS+k*2);
					}
					int x1=S%3,x2=S*3/MAXS,x3=(S*9/MAXS)%3;
					if(x1==2 && x2==0 && x3==1){
						Upd(f[i][j][1][S*3%MAXS+1],f[i][j-1][0][S]);
					}else{
						Upd(f[i][j][0][S*3%MAXS+1],f[i][j-1][0][S]);
					}
					Upd(f[i][j][1][S*3%MAXS+1],f[i][j-1][1][S]);
					//printf("sec %d -> %d\n",S,S*3%MAXS+1);
					//printf("@@@ %d %d %d %d\n",S,x1,x2,x3);
				}
				if(s[i][j]=='I'){
					Upd(f[i][j][0][S*3%MAXS+0],f[i][j-1][0][S]);
					Upd(f[i][j][1][S*3%MAXS+0],f[i][j-1][1][S]);
					//puts("FUCK!");
					//printf("sec %d -> %d : %d\n",S,S*3%MAXS+0,f[i][j][0][S*3%MAXS+0]);
				}
				if(s[i][j]=='C'){
					int x1=S%3,x2=S*3/MAXS,x3=(S*9/MAXS)%3;
					if(x1==2 && x2==0 && x3==1){
						Upd(f[i][j][1][S*3%MAXS+1],f[i][j-1][0][S]);
					}else{
						Upd(f[i][j][0][S*3%MAXS+1],f[i][j-1][0][S]);
					}
					Upd(f[i][j][1][S*3%MAXS+1],f[i][j-1][1][S]);
					//printf("sec %d -> %d\n",S,S*3%MAXS+1);
					//printf("@@@ %d %d %d %d\n",S,x1,x2,x3);
				}
				if(s[i][j]=='P'){
					Upd(f[i][j][0][S*3%MAXS+2],f[i][j-1][0][S]);
					Upd(f[i][j][1][S*3%MAXS+2],f[i][j-1][1][S]);
					//printf("%d -> %d\n",S,S*3%MAXS+2);
				}
			}
		}
	}
	int ans=0;
	rep(s,0,MAXS-1) Upd(ans,f[n][m][1][s]);
	printf("%d",ans);
	return 0;
}
/*
3 3
???
?I?
???
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3 3
???
?I?
???

output:


result: