QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#688254 | #5576. Advertising ICPC | Tenshi# | AC ✓ | 946ms | 211464kb | C++23 | 2.4kb | 2024-10-30 01:36:44 | 2024-10-30 01:36:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << (x) << endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define x first
#define y second
using pii = pair<int, int>;
using ll = long long;
// #define int ll
inline void read(int &x){
int s=0; x=1;
char ch=getchar();
while(ch<'0' || ch>'9') {if(ch=='-')x=-1;ch=getchar();}
while(ch>='0' && ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
x*=s;
}
const int N=10, mod=998244353;
int n, m;
char g[N][N];
int f[N][6661][2];
int U;
string get(int st){
string res;
rep(i, 1, m){
int t=st%3;
st/=3;
res+=t+'0';
}
return res;
}
vector<int> pre[6661], pre2[6661];
bool chk(string &s, string &t){
// t
// s
rep(i, 0, m-2){
if(s[i]=='2' && s[i+1]=='0' && t[i]=='1' && t[i+1]=='0') return true;
}
return false;
}
int add(int x, int y){
return x+y>=mod? x+y-mod: x+y;
}
string gt[16561];
signed main(){
cin>>n>>m;
rep(i, 1, n) rep(j, 0, m-1){
cin>>g[i][j];
if(g[i][j]=='C') g[i][j]='0';
if(g[i][j]=='I') g[i][j]='1';
if(g[i][j]=='P') g[i][j]='2';
}
U=1;
rep(j, 1, m) U*=3;
rep(st, 0, U-1) gt[st]=get(st);
rep(st, 0, U-1){
bool ok=true;
auto s=get(st);
rep(j, 0, m-1) if(isdigit(g[1][j]) && s[j]!=g[1][j]){
ok=false;
break;
}
f[1][st][0]=ok;
}
int tot=0;
rep(st, 0, U-1){
auto s=gt[st];
bool fl=false;
rep(j, 0, m-2) if(s[j]=='2' && s[j+1]=='0') fl=true;
rep(st2, 0, U-1){
auto t=gt[st2];
// pre[st].pb(st2);
if(fl && chk(s, t)) pre[st].pb(st2), ++tot;
else pre2[st].pb(st2);
}
}
// debug(tot);
rep(i, 2, n){
// rep(st1, 0, U-1) rep(st2, 0, U-1){
// f[i][st2][1]=add(f[i][st2][1], f[i-1][st1][1]);
// }
rep(st2, 0, U-1){
auto s=get(st2);
bool ok=true;
rep(j, 0, m-1) if(isdigit(g[i][j]) && s[j]!=g[i][j]){
ok=false;
break;
}
if(!ok) continue;
rep(st1, 0, U-1)
f[i][st2][1]=add(f[i][st2][1], f[i-1][st1][1]);
for(auto st1: pre[st2]){
f[i][st2][1]=add(f[i][st2][1], f[i-1][st1][0]);
}
for(auto st1: pre2[st2]){
f[i][st2][0]=add(f[i][st2][0], f[i-1][st1][0]);
}
}
}
int res=0;
rep(st, 0, U-1) res=add(res, f[n][st][1]);
cout<<res<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4172kb
input:
3 3 ??? ?I? ???
output:
243
result:
ok single line: '243'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4136kb
input:
2 2 IC PC
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 946ms
memory: 211464kb
input:
8 8 ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
output:
776529021
result:
ok single line: '776529021'
Test #4:
score: 0
Accepted
time: 0ms
memory: 4324kb
input:
2 2 ?? ??
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 4132kb
input:
2 2 CP CI
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 1ms
memory: 4140kb
input:
2 2 IP CC
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 4020kb
input:
2 2 PI CC
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 1ms
memory: 4364kb
input:
2 2 CI CP
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 398ms
memory: 211044kb
input:
2 8 ???P???? ???P??P?
output:
115443
result:
ok single line: '115443'
Test #10:
score: 0
Accepted
time: 403ms
memory: 211128kb
input:
2 8 IC???C?? ?I?IC?I?
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 388ms
memory: 210940kb
input:
2 8 ?????P?? I???C??I
output:
32562
result:
ok single line: '32562'
Test #12:
score: 0
Accepted
time: 381ms
memory: 210956kb
input:
2 8 ?PIC?CP? ?CIPC?IC
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 387ms
memory: 210980kb
input:
2 8 CCCPICPP PII?PCCP
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 1ms
memory: 4096kb
input:
8 2 P? ?? ?? ?? I? ?? ?P ??
output:
96957
result:
ok single line: '96957'
Test #15:
score: 0
Accepted
time: 1ms
memory: 4192kb
input:
8 2 ?? C? ?? ?? ?? ?? ?? I?
output:
234009
result:
ok single line: '234009'
Test #16:
score: 0
Accepted
time: 1ms
memory: 4100kb
input:
8 2 PI CC IC CI ?I P? CP CP
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 1ms
memory: 4160kb
input:
8 2 ?C II CC IP ?C C? PP ?I
output:
0
result:
ok single line: '0'
Test #18:
score: 0
Accepted
time: 1ms
memory: 4160kb
input:
8 2 PP PC ?I ?C II CC I? CI
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 438ms
memory: 211000kb
input:
3 8 ????I??? ???P???? ??????P?
output:
598932682
result:
ok single line: '598932682'
Test #20:
score: 0
Accepted
time: 448ms
memory: 210992kb
input:
3 8 ???C???? ???????C I???????
output:
176286317
result:
ok single line: '176286317'
Test #21:
score: 0
Accepted
time: 374ms
memory: 211024kb
input:
3 8 ?IPCI??I ?C?CIIP? ?PCP?P?C
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 378ms
memory: 210964kb
input:
3 8 I?IPCCC? ?CPCC?P? ?CCPCC?I
output:
486
result:
ok single line: '486'
Test #23:
score: 0
Accepted
time: 394ms
memory: 211108kb
input:
3 8 CPICCCIP CIP??CPC CPPPCIPC
output:
4
result:
ok single line: '4'
Test #24:
score: 0
Accepted
time: 1ms
memory: 4096kb
input:
8 3 ??? ??? ??? ??? I?? ??? ?P? ???
output:
181529684
result:
ok single line: '181529684'
Test #25:
score: 0
Accepted
time: 0ms
memory: 4196kb
input:
8 3 I?? ??? I?? ?C? ??P ?I? CII C?C
output:
966654
result:
ok single line: '966654'
Test #26:
score: 0
Accepted
time: 1ms
memory: 4356kb
input:
8 3 CC? ??I ??? I?C PCC C?C ??C ??I
output:
241974
result:
ok single line: '241974'
Test #27:
score: 0
Accepted
time: 0ms
memory: 4164kb
input:
8 3 IIP ??? IPI P?C I?P P?C CPI C?P
output:
243
result:
ok single line: '243'
Test #28:
score: 0
Accepted
time: 0ms
memory: 4044kb
input:
8 3 PCP PPP ?CC CPP C?P CP? CPC II?
output:
0
result:
ok single line: '0'
Test #29:
score: 0
Accepted
time: 630ms
memory: 211304kb
input:
8 8 ???????? ?P??C?P? ???????? ????I??? ?P????I? ???C???? ???????? C??????I
output:
694454028
result:
ok single line: '694454028'
Test #30:
score: 0
Accepted
time: 442ms
memory: 211156kb
input:
8 8 ????I?PI ???PC?I? ????IPC? ?????P?? PPIC???? ?P????I? ???????C C?????C?
output:
943439945
result:
ok single line: '943439945'
Test #31:
score: 0
Accepted
time: 396ms
memory: 211028kb
input:
8 8 PPPI???? ??P??PIC ?PC??CCP CPP????I ?II????C CIPCI??C C??PPC?? PI?PCCCC
output:
930881552
result:
ok single line: '930881552'
Test #32:
score: 0
Accepted
time: 402ms
memory: 211000kb
input:
8 8 IPPI?IPP ICPC?II? IICII??I ?PPCPPCC ?C??I?II ?ICCCCCI PIIP?IIP ?P??II?C
output:
4782969
result:
ok single line: '4782969'
Test #33:
score: 0
Accepted
time: 379ms
memory: 211056kb
input:
8 8 PCPICCPP IIICIICI PCCPIC?P IIPICIIC CPIC?ICI PCCI?C?? C?CC?IIC CCPIPICP
output:
0
result:
ok single line: '0'
Test #34:
score: 0
Accepted
time: 104ms
memory: 28440kb
input:
8 7 ??????? ??????? ??????C ??????? ??????? ??????? ??????? ???????
output:
407572405
result:
ok single line: '407572405'
Test #35:
score: 0
Accepted
time: 58ms
memory: 28192kb
input:
8 7 ??????P ????P?? PC???C? P?P???? ?CI?P?? ?????PI ????C?? C?PCI?P
output:
299705028
result:
ok single line: '299705028'
Test #36:
score: 0
Accepted
time: 44ms
memory: 28380kb
input:
8 7 IP?I?I? ??C??C? IPC???? P???C?? ??IP??? IPI???C P??PPI? ?PPICCC
output:
945285612
result:
ok single line: '945285612'
Test #37:
score: 0
Accepted
time: 49ms
memory: 28292kb
input:
8 7 ?PCPC?C P?IC?P? P?ICPPC ?C??P?? P?PICPI I?CCC?I I??PCPI PCIIIPP
output:
24011073
result:
ok single line: '24011073'
Test #38:
score: 0
Accepted
time: 41ms
memory: 28300kb
input:
8 7 CIC??II CCIIPPC IPCIPCP IC?IPPI PPCCPP? ICPPIIP PPPCI?I CIICI??
output:
0
result:
ok single line: '0'
Test #39:
score: 0
Accepted
time: 798ms
memory: 211236kb
input:
7 8 ???????? ???????? ?P?????? ???????? ???????? ???????? ????????
output:
335862381
result:
ok single line: '335862381'
Test #40:
score: 0
Accepted
time: 454ms
memory: 211184kb
input:
7 8 CI?P?P?? I?P?I??? ??????I? ???PP??? ?C????P? ?P?????? ?PI?I??I
output:
371435886
result:
ok single line: '371435886'
Test #41:
score: 0
Accepted
time: 418ms
memory: 211076kb
input:
7 8 ICI?II?C ???C???? I?IC??I? ??CC???? C????CCI P??I??II C??I?PCP
output:
220669500
result:
ok single line: '220669500'
Test #42:
score: 0
Accepted
time: 395ms
memory: 211144kb
input:
7 8 CPI?CP?C I?P??PPI P?CCCPP? PIC?I?PP IPII?PII CIPCCP?? IIC???IP
output:
3483891
result:
ok single line: '3483891'
Test #43:
score: 0
Accepted
time: 393ms
memory: 211056kb
input:
7 8 IIICICII IIPPPCIP ICCP?C?C CPIP??IC IIICICII C?CPPPII CIPPCPCC
output:
243
result:
ok single line: '243'
Test #44:
score: 0
Accepted
time: 79ms
memory: 28412kb
input:
7 7 ???C??? ??????? ??????? P?????P ??????? I?????C ???????
output:
45031736
result:
ok single line: '45031736'
Test #45:
score: 0
Accepted
time: 53ms
memory: 28360kb
input:
7 7 ?P?C?I? ?????C? ??I?P?? ?CICPCC ???P??I IIPP?I? ???P???
output:
414440826
result:
ok single line: '414440826'
Test #46:
score: 0
Accepted
time: 42ms
memory: 28060kb
input:
7 7 ??I?P?C ?I?PIPC C???PPI I????PI PP?I?PC P?IIC?? IPC??CC
output:
623536432
result:
ok single line: '623536432'
Test #47:
score: 0
Accepted
time: 41ms
memory: 28312kb
input:
7 7 I??PCP? IPP?CCP IPIP?II P?CCPP? ?CP???P PPIC??C ??IPCPP
output:
1751787
result:
ok single line: '1751787'
Test #48:
score: 0
Accepted
time: 40ms
memory: 28096kb
input:
7 7 I?PPPPC CIIICPP CCCPPPP PP?PCIP IIIIIPI ICIPCII ?ICPPCI
output:
0
result:
ok single line: '0'