QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#259443 | #5576. Advertising ICPC | anton_h# | AC ✓ | 19ms | 4936kb | C++20 | 2.6kb | 2023-11-20 22:17:49 | 2023-11-20 22:17:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define sz(c) ll((c).size())
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)
#define all(c) begin(c),end(c)
#define pb push_back
#define FORD(i, a, b) for(ll i=(b)-1;i>=(a);i--)
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
#define xx first
#define yy second
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl;})
const ll MOD = 998'244'353;
ll mp(char c) {
if (c == 'I') return 0;
if (c == 'C') return 1;
if (c == 'P') return 2;
return -1;
}
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
ll n, m;
cin >> n >> m;
vector<string> field(n);
for (auto &s: field) cin >> s;
vl pot(m + 2);
pot[0] = 1;
FOR(i, 1, sz(pot)) pot[i] = 3 * pot[i - 1];
vector<string> starts = {""};
FOR(i, 0, m) {
vector<string> next;
vector<char> poss = {'I', 'C', 'P'};
for (auto s: starts) {
if (field[0][i] != '?')
poss = {field[0][i]};
for (char c: poss) {
string sx = s + c;
next.pb(sx);
}
}
starts = next;
}
vector<string> next;
vector<char> nec = {'I', 'C', 'P'};
for (auto s: starts) {
if (field[1][0] != '?')
nec = {field[1][0]};
for (char c: nec) {
string sx = s + c;
next.pb(sx);
}
}
starts = next;
vl poss(pot[m + 1]), non(pot[m + 1]);
for (string s: starts) {
ll val = 0;
FOR(i, 0, m + 1) {
val *= 3;
val += mp(s[i]);
}
poss[val] = 1;
non[val] = 1;
}
FOR(i, 1, n) FOR(j, 0, m) {
if(i == 1 && j == 0)
continue;
vector<char> ne = {'I', 'C', 'P'};
if (field[i][j] != '?')
ne = {field[i][j]};
vl nextPoss(pot[m + 1]), nextNon(pot[m + 1]);
FOR(val, 0, pot[m + 1]) {
for(char c : ne){
ll nextVal = (val * 3) % pot[m + 1] + mp(c);
if(j == 0 || c != 'C' || mp('P') != val % 3 || mp('I') != val / pot[m] || mp('C') != (val % pot[m]) / pot[m - 1]){
nextNon[nextVal] = (nextNon[nextVal] + non[val]) % MOD;
}
nextPoss[nextVal] = (nextPoss[nextVal] + poss[val]) % MOD;
}
}
poss = nextPoss;
non = nextNon;
}
ll ans = 0;
ll sum = 0;
FOR(i, 0, pot[m + 1]) ans += poss[i] - non[i];
ans = ((ans % MOD) + MOD) % MOD;
cout << ans << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
3 3 ??? ?I? ???
output:
243
result:
ok single line: '243'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
2 2 IC PC
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 19ms
memory: 4872kb
input:
8 8 ???????? ???????? ???????? ???????? ???????? ???????? ???????? ????????
output:
776529021
result:
ok single line: '776529021'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
2 2 ?? ??
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
2 2 CP CI
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
2 2 IP CC
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
2 2 PI CC
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
2 2 CI CP
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 0ms
memory: 4412kb
input:
2 8 ???P???? ???P??P?
output:
115443
result:
ok single line: '115443'
Test #10:
score: 0
Accepted
time: 2ms
memory: 4116kb
input:
2 8 IC???C?? ?I?IC?I?
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 3ms
memory: 3960kb
input:
2 8 ?????P?? I???C??I
output:
32562
result:
ok single line: '32562'
Test #12:
score: 0
Accepted
time: 2ms
memory: 3896kb
input:
2 8 ?PIC?CP? ?CIPC?IC
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3864kb
input:
2 8 CCCPICPP PII?PCCP
output:
3
result:
ok single line: '3'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
8 2 P? ?? ?? ?? I? ?? ?P ??
output:
96957
result:
ok single line: '96957'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
8 2 ?? C? ?? ?? ?? ?? ?? I?
output:
234009
result:
ok single line: '234009'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
8 2 PI CC IC CI ?I P? CP CP
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
8 2 ?C II CC IP ?C C? PP ?I
output:
0
result:
ok single line: '0'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
8 2 PP PC ?I ?C II CC I? CI
output:
0
result:
ok single line: '0'
Test #19:
score: 0
Accepted
time: 6ms
memory: 4420kb
input:
3 8 ????I??? ???P???? ??????P?
output:
598932682
result:
ok single line: '598932682'
Test #20:
score: 0
Accepted
time: 3ms
memory: 4284kb
input:
3 8 ???C???? ???????C I???????
output:
176286317
result:
ok single line: '176286317'
Test #21:
score: 0
Accepted
time: 2ms
memory: 3884kb
input:
3 8 ?IPCI??I ?C?CIIP? ?PCP?P?C
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 4ms
memory: 4056kb
input:
3 8 I?IPCCC? ?CPCC?P? ?CCPCC?I
output:
486
result:
ok single line: '486'
Test #23:
score: 0
Accepted
time: 3ms
memory: 3848kb
input:
3 8 CPICCCIP CIP??CPC CPPPCIPC
output:
4
result:
ok single line: '4'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
8 3 ??? ??? ??? ??? I?? ??? ?P? ???
output:
181529684
result:
ok single line: '181529684'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3640kb
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: 3568kb
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: 3600kb
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: 3560kb
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: 17ms
memory: 4856kb
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: 3956kb
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: 10ms
memory: 3880kb
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: 10ms
memory: 3884kb
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: 7ms
memory: 3884kb
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: 6ms
memory: 4100kb
input:
8 7 ??????? ??????? ??????C ??????? ??????? ??????? ??????? ???????
output:
407572405
result:
ok single line: '407572405'
Test #35:
score: 0
Accepted
time: 5ms
memory: 3800kb
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: 4ms
memory: 3756kb
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: 3ms
memory: 3760kb
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: 3ms
memory: 3772kb
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: 16ms
memory: 4936kb
input:
7 8 ???????? ???????? ?P?????? ???????? ???????? ???????? ????????
output:
335862381
result:
ok single line: '335862381'
Test #40:
score: 0
Accepted
time: 11ms
memory: 4080kb
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: 8ms
memory: 3836kb
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: 11ms
memory: 3912kb
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: 9ms
memory: 3912kb
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: 4ms
memory: 4048kb
input:
7 7 ???C??? ??????? ??????? P?????P ??????? I?????C ???????
output:
45031736
result:
ok single line: '45031736'
Test #45:
score: 0
Accepted
time: 0ms
memory: 3980kb
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: 3ms
memory: 3688kb
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: 3ms
memory: 3712kb
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: 3708kb
input:
7 7 I?PPPPC CIIICPP CCCPPPP PP?PCIP IIIIIPI ICIPCII ?ICPPCI
output:
0
result:
ok single line: '0'