QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#474799 | #8552. Sticks | real_sigma_team | AC ✓ | 545ms | 192016kb | C++20 | 2.8kb | 2024-07-13 05:01:53 | 2024-07-13 05:01:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int mod = 998244353;
int add(int a, int b) {
return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a, int b) {
return a >= b ? a - b : a + mod - b;
}
int mul(int a, int b) {
return 1ll * a * b % mod;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
vector<string> a(n);
for (auto& i : a) cin >> i;
vector<vector<int>> dp(n + 1, vector<int>(n + 1, 1));
vector<vector<int>> lft(n, vector<int>(n, -1)), up(n, vector<int>(n, -1));
vector<vector<int>> rgt(n, vector<int>(n, 0)), down(n, vector<int>(n, 0));
vector<vector<bool>> zero_lft(n, vector<bool>(n, false)), zero_up(n, vector<bool>(n, false));
for (int i = 0; i < n; ++i) {
int cur = -1;
for (int j = 0; j < n; ++j) {
if (a[i][j] == '1') cur = j;
lft[i][j] = cur;
}
}
for (int j = 0; j < n; ++j) {
int cur = -1;
for (int i = 0; i < n; ++i) {
if (a[i][j] == '1') cur = i;
up[i][j] = cur;
}
}
for (int i = 0; i < n; ++i) {
int cur = 0;
for (int j = n - 1; j >= 0; --j) {
if (a[i][j] == '0') cur = 0;
else cur++;
rgt[i][j] = cur;
}
}
for (int j = 0; j < n; ++j) {
int cur = 0;
for (int i = n - 1; i >= 0; --i) {
if (a[i][j] == '0') cur = 0;
else cur++;
down[i][j] = cur;
}
}
for (int i = 0; i < n; ++i) {
bool cur = false;
for (int j = 0; j < n; ++j) {
cur |= a[i][j] == '0';
zero_lft[i][j] = cur;
}
}
for (int j = 0; j < n; ++j) {
bool cur = false;
for (int i = 0; i < n; ++i) {
cur |= a[i][j] == '0';
zero_up[i][j] = cur;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
int ret = 0;
int l1, r1, l2, r2;
l1 = lft[i][j];
r1 = max(l1, 0) + rgt[i][max(l1, 0)] - 1;
l2 = up[i][j];
r2 = max(l2, 0) + down[max(l2, 0)][j] - 1;
r1 = min(r1, j);
r2 = min(r2, i);
if (l1 < 0 || !zero_lft[i][l1]) ret = add(ret, mul(r1 - l1 + 1, dp[i][j + 1]));
if (l2 < 0 || !zero_up[l2][j]) ret = add(ret, mul(r2 - l2 + 1, dp[i + 1][j]));
r1 = min(r1, j - 1);
r2 = min(r2, i - 1);
if ((l1 < 0 || !zero_lft[i][l1]) && (l2 < 0 || !zero_up[l2][j])) ret = sub(ret, mul(mul(r1 - l1 + 1, r2 - l2 + 1), dp[i][j]));
if (!zero_lft[i][j] && !zero_up[i][j]) ret = sub(ret, dp[i][j]);
dp[i + 1][j + 1] = ret;
}
}
cout << dp[n][n] << '\n';
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
input:
2 ?? ??
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
5 ??1?? ?1??0 ??0?? ???1? ??1??
output:
3144
result:
ok 1 number(s): "3144"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
10 0000000000 ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ??????????
output:
361458985
result:
ok 1 number(s): "361458985"
Test #4:
score: 0
Accepted
time: 408ms
memory: 191784kb
input:
3000 ??????????????????????????????????????????????????????????0?????????????????????0??????????????????????????????????????????????????????????????????????????????????????0???????????????????????????????????????????0???????????????????????????????????????????????????????????????????????????????????...
output:
56427841
result:
ok 1 number(s): "56427841"
Test #5:
score: 0
Accepted
time: 439ms
memory: 191780kb
input:
3000 ????????????????????????????????????????0??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
145247225
result:
ok 1 number(s): "145247225"
Test #6:
score: 0
Accepted
time: 485ms
memory: 191992kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
925248762
result:
ok 1 number(s): "925248762"
Test #7:
score: 0
Accepted
time: 515ms
memory: 192016kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
845505610
result:
ok 1 number(s): "845505610"
Test #8:
score: 0
Accepted
time: 511ms
memory: 191988kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
123028256
result:
ok 1 number(s): "123028256"
Test #9:
score: 0
Accepted
time: 530ms
memory: 191816kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1???1??????????????????????????????????????????????????????????????????????1????????????????????????????????????????????????????????????????...
output:
242286033
result:
ok 1 number(s): "242286033"
Test #10:
score: 0
Accepted
time: 545ms
memory: 192016kb
input:
3000 ??????????????????????????1????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
448817936
result:
ok 1 number(s): "448817936"
Test #11:
score: 0
Accepted
time: 518ms
memory: 191856kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
621258555
result:
ok 1 number(s): "621258555"
Test #12:
score: 0
Accepted
time: 507ms
memory: 191944kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
552098298
result:
ok 1 number(s): "552098298"
Test #13:
score: 0
Accepted
time: 523ms
memory: 192000kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
190431651
result:
ok 1 number(s): "190431651"
Test #14:
score: 0
Accepted
time: 490ms
memory: 191788kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 518ms
memory: 191888kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
641634738
result:
ok 1 number(s): "641634738"
Test #16:
score: 0
Accepted
time: 528ms
memory: 191892kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
434138343
result:
ok 1 number(s): "434138343"
Test #17:
score: 0
Accepted
time: 516ms
memory: 192016kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
70334815
result:
ok 1 number(s): "70334815"
Test #18:
score: 0
Accepted
time: 504ms
memory: 191756kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
26692788
result:
ok 1 number(s): "26692788"
Test #19:
score: 0
Accepted
time: 518ms
memory: 191820kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
513359183
result:
ok 1 number(s): "513359183"
Test #20:
score: 0
Accepted
time: 514ms
memory: 191888kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
144382583
result:
ok 1 number(s): "144382583"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
2 10 01
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 413ms
memory: 191824kb
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: 419ms
memory: 191940kb
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: 376ms
memory: 191944kb
input:
3000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1
result:
ok 1 number(s): "1"
Test #27:
score: 0
Accepted
time: 386ms
memory: 191884kb
input:
3000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1
result:
ok 1 number(s): "1"
Extra Test:
score: 0
Extra Test Passed