QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#333538#5576. Advertising ICPCjoelgun14#AC ✓21ms25328kbC++143.4kb2024-02-20 06:57:072024-02-20 06:57:08

Judging History

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

  • [2024-02-20 06:57:08]
  • 评测
  • 测评结果:AC
  • 用时:21ms
  • 内存:25328kb
  • [2024-02-20 06:57:07]
  • 提交

answer

#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define getbit(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
    if (a < b) {a = b; return true;} return false;
}

template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
    if (a > b) {a = b; return true;} return false;
}

const long MOD = 998244353;
const int N = 2e5 + 5;
const int oo = 1e9;
const long long ooo = 1e18;

int n, m;
char pet[10][10];
ll dp[9][9][20000][2];
ll pw3[101];

int bit(int mask, int x)
{
    return (mask/pw3[x])%pw3[x+1];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);  
    pw3[0] = 1;
    for(int i = 1; i <= 20; i++)
    {
        pw3[i] = pw3[i-1]*3;
    }


    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cin >> pet[i][j];
            // cout << pet[i][j];
        }
        // cout << "\n";
    }
    if(pet[1][1] == 'I' || pet[1][1] == '?') 
    {
        dp[1][1][0][0] = 1;
    }
    if(pet[1][1] == 'C' || pet[1][1] == '?') 
    {
        dp[1][1][1][0] = 1;
    }
    if(pet[1][1] == 'P' || pet[1][1] == '?') 
    {
        dp[1][1][2][0] = 1;
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            for(int k = 0; k < pw3[m+1]; k++)
            {
                // cout << i << " " << j << " " << k << " " << dp[i][j][k][0] << " " << dp[i][j][k][1] << "\n";
                int mask = k;
                int _i = i;
                int _j = j+1;
                if(_j == m+1) _i = i+1, _j = 1;
                if(pet[_i][_j] == 'I' || pet[_i][_j] == '?')
                {
                    dp[_i][_j][(mask%pw3[m])*3+0][0] += dp[i][j][mask][0];
                    dp[_i][_j][(mask%pw3[m])*3+0][0] %= MOD;
                    dp[_i][_j][(mask%pw3[m])*3+0][1] += dp[i][j][mask][1];
                    dp[_i][_j][(mask%pw3[m])*3+0][1] %= MOD;
                }
                if(pet[_i][_j] == 'P' || pet[_i][_j] == '?')
                {
                    dp[_i][_j][(mask%pw3[m])*3+2][0] += dp[i][j][mask][0];
                    dp[_i][_j][(mask%pw3[m])*3+2][0] %= MOD;
                    dp[_i][_j][(mask%pw3[m])*3+2][1] += dp[i][j][mask][1];
                    dp[_i][_j][(mask%pw3[m])*3+2][1] %= MOD;
                }
                if(pet[_i][_j] == 'C' || pet[_i][_j] == '?')
                {
                    if(bit(mask,m) == 0 && bit(mask,m-1) == 1 && bit(mask,0) == 2 && _j != 1)
                    {
                        dp[_i][_j][(mask%pw3[m])*3+1][1] += dp[i][j][mask][0];
                        dp[_i][_j][(mask%pw3[m])*3+1][1] %= MOD;
                    }
                    else
                    {
                        dp[_i][_j][(mask%pw3[m])*3+1][0] += dp[i][j][mask][0];
                        dp[_i][_j][(mask%pw3[m])*3+1][0] %= MOD;
                    }
                    dp[_i][_j][(mask%pw3[m])*3+1][1] += dp[i][j][mask][1];
                    dp[_i][_j][(mask%pw3[m])*3+1][1] %= MOD;
                }
            }
        }
    }

    long ans = 0;
    for(int mask = 0; mask < pw3[m+1]; mask++)
    {
        ans += dp[n][m][mask][1];
        ans %= MOD;
    }
    cout << ans << "\n";
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5748kb

input:

3 3
???
?I?
???

output:

243

result:

ok single line: '243'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5728kb

input:

2 2
IC
PC

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 21ms
memory: 24944kb

input:

8 8
????????
????????
????????
????????
????????
????????
????????
????????

output:

776529021

result:

ok single line: '776529021'

Test #4:

score: 0
Accepted
time: 0ms
memory: 5784kb

input:

2 2
??
??

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 5720kb

input:

2 2
CP
CI

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5648kb

input:

2 2
IP
CC

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 5776kb

input:

2 2
PI
CC

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 1ms
memory: 5696kb

input:

2 2
CI
CP

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 6ms
memory: 9552kb

input:

2 8
???P????
???P??P?

output:

115443

result:

ok single line: '115443'

Test #10:

score: 0
Accepted
time: 0ms
memory: 9732kb

input:

2 8
IC???C??
?I?IC?I?

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 6ms
memory: 9436kb

input:

2 8
?????P??
I???C??I

output:

32562

result:

ok single line: '32562'

Test #12:

score: 0
Accepted
time: 5ms
memory: 9892kb

input:

2 8
?PIC?CP?
?CIPC?IC

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 0ms
memory: 9036kb

input:

2 8
CCCPICPP
PII?PCCP

output:

3

result:

ok single line: '3'

Test #14:

score: 0
Accepted
time: 1ms
memory: 5700kb

input:

8 2
P?
??
??
??
I?
??
?P
??

output:

96957

result:

ok single line: '96957'

Test #15:

score: 0
Accepted
time: 1ms
memory: 5700kb

input:

8 2
??
C?
??
??
??
??
??
I?

output:

234009

result:

ok single line: '234009'

Test #16:

score: 0
Accepted
time: 1ms
memory: 5772kb

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: 5784kb

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: 5768kb

input:

8 2
PP
PC
?I
?C
II
CC
I?
CI

output:

0

result:

ok single line: '0'

Test #19:

score: 0
Accepted
time: 4ms
memory: 12068kb

input:

3 8
????I???
???P????
??????P?

output:

598932682

result:

ok single line: '598932682'

Test #20:

score: 0
Accepted
time: 0ms
memory: 11804kb

input:

3 8
???C????
???????C
I???????

output:

176286317

result:

ok single line: '176286317'

Test #21:

score: 0
Accepted
time: 3ms
memory: 11752kb

input:

3 8
?IPCI??I
?C?CIIP?
?PCP?P?C

output:

0

result:

ok single line: '0'

Test #22:

score: 0
Accepted
time: 0ms
memory: 12760kb

input:

3 8
I?IPCCC?
?CPCC?P?
?CCPCC?I

output:

486

result:

ok single line: '486'

Test #23:

score: 0
Accepted
time: 3ms
memory: 12756kb

input:

3 8
CPICCCIP
CIP??CPC
CPPPCIPC

output:

4

result:

ok single line: '4'

Test #24:

score: 0
Accepted
time: 1ms
memory: 5800kb

input:

8 3
???
???
???
???
I??
???
?P?
???

output:

181529684

result:

ok single line: '181529684'

Test #25:

score: 0
Accepted
time: 0ms
memory: 5832kb

input:

8 3
I??
???
I??
?C?
??P
?I?
CII
C?C

output:

966654

result:

ok single line: '966654'

Test #26:

score: 0
Accepted
time: 0ms
memory: 5832kb

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: 1ms
memory: 5768kb

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: 1ms
memory: 5832kb

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: 12ms
memory: 23748kb

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: 13ms
memory: 25032kb

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: 7ms
memory: 25328kb

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: 4ms
memory: 24388kb

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: 15ms
memory: 24280kb

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: 3ms
memory: 11196kb

input:

8 7
???????
???????
??????C
???????
???????
???????
???????
???????

output:

407572405

result:

ok single line: '407572405'

Test #35:

score: 0
Accepted
time: 7ms
memory: 11252kb

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: 6ms
memory: 10864kb

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: 6ms
memory: 11180kb

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: 0ms
memory: 10984kb

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: 10ms
memory: 21428kb

input:

7 8
????????
????????
?P??????
????????
????????
????????
????????

output:

335862381

result:

ok single line: '335862381'

Test #40:

score: 0
Accepted
time: 10ms
memory: 22796kb

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: 11ms
memory: 21648kb

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: 8ms
memory: 21436kb

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: 6ms
memory: 22684kb

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: 3ms
memory: 10488kb

input:

7 7
???C???
???????
???????
P?????P
???????
I?????C
???????

output:

45031736

result:

ok single line: '45031736'

Test #45:

score: 0
Accepted
time: 6ms
memory: 10420kb

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: 5ms
memory: 10444kb

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: 2ms
memory: 10412kb

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: 0ms
memory: 10452kb

input:

7 7
I?PPPPC
CIIICPP
CCCPPPP
PP?PCIP
IIIIIPI
ICIPCII
?ICPPCI

output:

0

result:

ok single line: '0'