QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720398 | #8552. Sticks | SkyMaths | AC ✓ | 180ms | 154076kb | C++20 | 2.8kb | 2024-11-07 12:26:40 | 2024-11-07 12:26:40 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i(l), i##end(r); i <= i##end; ++i)
#define per(i,r,l) for (int i(r), i##end(l); i >= i##end; --i)
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define uint unsigned int
#define eb emplace_back
#define File(filename) freopen(filename".in", "r", stdin), freopen(filename".out", "w", stdout)
using namespace std;
template <typename Tx> inline void read(Tx &x) {x = 0; bool f = 0; char ch = getchar(); while (ch < '0' || ch > '9') f ^= ch == '-', ch = getchar(); while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); if (f) x = -x;}
template <typename Tx, typename ...Ty> inline void read(Tx &x, Ty &...y) {read(x); read(y...);}
template <typename Tx> inline void owrite(Tx x) {if (x > 9) owrite(x / 10); putchar('0' + x % 10);}
template <typename Tx> inline void write(Tx x, char ch = '\n') {owrite(x < 0 ? (putchar('-'), -x) : x); putchar(ch);}
template <typename Tx> inline void cmax(Tx &x, Tx y) {if (x < y) x = y;}
template <typename Tx> inline void cmin(Tx &x, Tx y) {if (x > y) x = y;}
namespace Main {
const int N = 3e3 + 9;
const int mod = 998244353;
int n;
int f[N][N], g[N][N], B[N], C[N][N], R[N][N];
char M[N][N];
bool b0(int i, int j) { return M[i][j] == '?' || M[i][j] == '0';}
bool b1(int i, int j) { return M[i][j] == '?' || M[i][j] == '1';}
void add(int &a, int b) {(a += b) >= mod && (a -= mod);}
void skymaths() {
read(n);
rep (i, 1, n) scanf(" %s", M[i] + 1);
rep (j, 1, n) {
int x = 0; while (x < n && b1(x + 1, j)) ++x;
B[j] = x;
}
// R : 行
// C : 列
rep (i, 1, n) {
int r = 0;
rep (l, 0, n) {
if (l && !b1(i, l)) break;
cmax(r, l); if (r == l) while (r < n && b0(i, r + 1)) ++r;
++R[i][l]; --R[i][r + 1];
}
rep (j, 1, n) R[i][j] += R[i][j - 1];
}
rep (j, 1, n) {
int r = 0;
rep (l, 0, n) {
if (l && !b1(l, j)) break;
cmax(r, l); if (r == l) while (r < n && b0(r + 1, j)) ++r;
++C[l][j]; --C[r + 1][j];
}
rep (i, 1, n) C[i][j] += C[i - 1][j];
}
f[0][1] = 1;
rep (i, 0, n) {
rep (j, 1, n) {
if (i == 0 && j == 1) continue;
f[i][j] = 1ll * f[i][j - 1] * C[i][j] % mod;
if (i > 0) {
g[i][j] = 1ll * (g[i - 1][j] + f[i - 1][j]) * R[i][j] % mod;
if (j > 1 && B[j] >= i && b0(i, j - 1)) add(f[i][j], 1ll * (f[i - 1][j - 1] + g[i - 1][j - 1]) * R[i][j - 2] % mod);
}
}
}
write((f[n][n] + g[n][n]) % mod);
}
signed main() {
// freopen("a.in", "r", stdin);
int T = 1;
// read(T);
while (T--) {
skymaths();
}
return 0;
} } signed main() { Main::main(); return 0;}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11776kb
input:
2 ?? ??
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 0ms
memory: 12004kb
input:
5 ??1?? ?1??0 ??0?? ???1? ??1??
output:
3144
result:
ok 1 number(s): "3144"
Test #3:
score: 0
Accepted
time: 1ms
memory: 11956kb
input:
10 0000000000 ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ??????????
output:
361458985
result:
ok 1 number(s): "361458985"
Test #4:
score: 0
Accepted
time: 152ms
memory: 154004kb
input:
3000 ??????????????????????????????????????????????????????????0?????????????????????0??????????????????????????????????????????????????????????????????????????????????????0???????????????????????????????????????????0???????????????????????????????????????????????????????????????????????????????????...
output:
56427841
result:
ok 1 number(s): "56427841"
Test #5:
score: 0
Accepted
time: 180ms
memory: 154008kb
input:
3000 ????????????????????????????????????????0??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
145247225
result:
ok 1 number(s): "145247225"
Test #6:
score: 0
Accepted
time: 151ms
memory: 153952kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
925248762
result:
ok 1 number(s): "925248762"
Test #7:
score: 0
Accepted
time: 148ms
memory: 154044kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
845505610
result:
ok 1 number(s): "845505610"
Test #8:
score: 0
Accepted
time: 159ms
memory: 153944kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
123028256
result:
ok 1 number(s): "123028256"
Test #9:
score: 0
Accepted
time: 143ms
memory: 154072kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1???1??????????????????????????????????????????????????????????????????????1????????????????????????????????????????????????????????????????...
output:
242286033
result:
ok 1 number(s): "242286033"
Test #10:
score: 0
Accepted
time: 160ms
memory: 154072kb
input:
3000 ??????????????????????????1????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
448817936
result:
ok 1 number(s): "448817936"
Test #11:
score: 0
Accepted
time: 158ms
memory: 153952kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
621258555
result:
ok 1 number(s): "621258555"
Test #12:
score: 0
Accepted
time: 170ms
memory: 153864kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
552098298
result:
ok 1 number(s): "552098298"
Test #13:
score: 0
Accepted
time: 113ms
memory: 154008kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
190431651
result:
ok 1 number(s): "190431651"
Test #14:
score: 0
Accepted
time: 176ms
memory: 154072kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 152ms
memory: 153988kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
641634738
result:
ok 1 number(s): "641634738"
Test #16:
score: 0
Accepted
time: 144ms
memory: 154076kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
434138343
result:
ok 1 number(s): "434138343"
Test #17:
score: 0
Accepted
time: 98ms
memory: 153804kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
70334815
result:
ok 1 number(s): "70334815"
Test #18:
score: 0
Accepted
time: 145ms
memory: 154048kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
26692788
result:
ok 1 number(s): "26692788"
Test #19:
score: 0
Accepted
time: 154ms
memory: 153860kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
513359183
result:
ok 1 number(s): "513359183"
Test #20:
score: 0
Accepted
time: 169ms
memory: 153852kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
144382583
result:
ok 1 number(s): "144382583"
Test #21:
score: 0
Accepted
time: 0ms
memory: 12016kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 0
Accepted
time: 0ms
memory: 12036kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #23:
score: 0
Accepted
time: 0ms
memory: 13820kb
input:
2 10 01
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 136ms
memory: 153988kb
input:
3000 1???11111??1???1?1?1111?1111??11?11?????11?1?1?1?1?1???111???111???11?1???11?11??1?11???1??111???11??1????1??1?111??1111?1??1?1?1?1111?1??11?111?1?1??11???11?1?1111??11???????1????1???1?1??111?11?1??1111?1111?1????11?11?1??1?1???1????11?1111?1?1?1??1111???1?11?111?1????1?1?11?11???1???????111?1...
output:
354584112
result:
ok 1 number(s): "354584112"
Test #25:
score: 0
Accepted
time: 141ms
memory: 153852kb
input:
3000 111?1111??11??1?1??1???1?????111???1?11111??1?111?1??1?1????11?11111??1??1?11??11????1??11??11?1???1111???1?11?111?11?1???1?11?11?111?11??1???????1?1??11?1111??????1?1??1111????111111111???1?111??1???111???1?11??11?1??1?11??1?1?111?????1??11?1????1???11??1?11?11111?1111??1?1?1?1???1?11111?1?111...
output:
46093564
result:
ok 1 number(s): "46093564"
Test #26:
score: 0
Accepted
time: 94ms
memory: 153948kb
input:
3000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1
result:
ok 1 number(s): "1"
Test #27:
score: 0
Accepted
time: 86ms
memory: 153860kb
input:
3000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1
result:
ok 1 number(s): "1"
Extra Test:
score: 0
Extra Test Passed