QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#82555 | #5576. Advertising ICPC | Yanagi_Origami | RE | 0ms | 0kb | C++14 | 2.9kb | 2023-02-28 03:42:22 | 2023-02-28 03:42:24 |
Judging History
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? ???