QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414586 | #8552. Sticks | enzopsm | AC ✓ | 207ms | 225060kb | C++20 | 2.3kb | 2024-05-19 10:45:27 | 2024-05-19 10:45:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
typedef pair<int, int> pii;
const int inf=INT_MAX;
const int maxn=3010;
const int md=998244353;
int n;
char mat[maxn][maxn];
int dp[maxn][maxn];
int cf0[maxn];
int lf0[maxn];
int lult1[maxn][maxn];
int cult1[maxn][maxn];
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios::sync_with_stdio(0);cin.tie(0);
cin>> n;
for(int i=1; i<=n; i++)
{
string s; cin>> s;
for(int j=1; j<=n; j++)
mat[i][j] = s[j-1];
}
for(int i=1; i<=n; i++)
{
lf0[i] = n+1;
for(int j=n; j>=1; j--)
if(mat[i][j] == '0')
lf0[i] = j;
int ult1 = 0;
for(int j=1; j<=n; j++)
{
if(mat[i][j] == '1')
ult1 = j;
lult1[i][j] = ult1;
}
}
for(int j=1; j<=n; j++)
{
cf0[j] = n+1;
for(int i=n; i>=1; i--)
if(mat[i][j] == '0')
cf0[j] = i;
int ult1 = 0;
for(int i=1; i<=n; i++)
{
if(mat[i][j] == '1')
ult1 = i;
cult1[i][j] = ult1;
}
}
for(int i=0; i<=n; i++)
{
for(int j=0; j<=n; j++)
{
if(i == 0 || j == 0)
{
dp[i][j] = 1;
continue;
}
int ult1i = cult1[i][j];
int ult1j = lult1[i][j];
if(i < cf0[j]) dp[i][j] += dp[i][j-1]; // tudo 1 ultima coluna
if(j < lf0[i]) dp[i][j] += dp[i-1][j]; // tudo 1 ultima linha
if(i < cf0[j] && j < lf0[i]) dp[i][j] -= dp[i-1][j-1]; // tudo 1 ultima coluna e linha
// os casos acima são os casos em que (i, j) é 1, suponha que (i, j) é 0
int a = max((ll)0, min(j, lf0[i]) - ult1j), b = max((ll)0, min(i, cf0[j]) - ult1i), c = a * b;
dp[i][j] += dp[i-1][j] * a % md + dp[i][j-1] * b % md - dp[i-1][j-1] * c % md;
while(dp[i][j] >= md) dp[i][j] -= md; while(dp[i][j] < 0) dp[i][j] += md;
}
}
cout<< dp[n][n]<< "\n";
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9640kb
input:
2 ?? ??
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9712kb
input:
5 ??1?? ?1??0 ??0?? ???1? ??1??
output:
3144
result:
ok 1 number(s): "3144"
Test #3:
score: 0
Accepted
time: 2ms
memory: 11748kb
input:
10 0000000000 ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ??????????
output:
361458985
result:
ok 1 number(s): "361458985"
Test #4:
score: 0
Accepted
time: 140ms
memory: 224828kb
input:
3000 ??????????????????????????????????????????????????????????0?????????????????????0??????????????????????????????????????????????????????????????????????????????????????0???????????????????????????????????????????0???????????????????????????????????????????????????????????????????????????????????...
output:
56427841
result:
ok 1 number(s): "56427841"
Test #5:
score: 0
Accepted
time: 189ms
memory: 224848kb
input:
3000 ????????????????????????????????????????0??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
145247225
result:
ok 1 number(s): "145247225"
Test #6:
score: 0
Accepted
time: 190ms
memory: 224760kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
925248762
result:
ok 1 number(s): "925248762"
Test #7:
score: 0
Accepted
time: 191ms
memory: 225060kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
845505610
result:
ok 1 number(s): "845505610"
Test #8:
score: 0
Accepted
time: 185ms
memory: 224704kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
123028256
result:
ok 1 number(s): "123028256"
Test #9:
score: 0
Accepted
time: 201ms
memory: 224848kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1???1??????????????????????????????????????????????????????????????????????1????????????????????????????????????????????????????????????????...
output:
242286033
result:
ok 1 number(s): "242286033"
Test #10:
score: 0
Accepted
time: 181ms
memory: 224664kb
input:
3000 ??????????????????????????1????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
448817936
result:
ok 1 number(s): "448817936"
Test #11:
score: 0
Accepted
time: 183ms
memory: 224716kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
621258555
result:
ok 1 number(s): "621258555"
Test #12:
score: 0
Accepted
time: 183ms
memory: 224784kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
552098298
result:
ok 1 number(s): "552098298"
Test #13:
score: 0
Accepted
time: 170ms
memory: 224848kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
190431651
result:
ok 1 number(s): "190431651"
Test #14:
score: 0
Accepted
time: 178ms
memory: 224768kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 185ms
memory: 224788kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
641634738
result:
ok 1 number(s): "641634738"
Test #16:
score: 0
Accepted
time: 206ms
memory: 224788kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
434138343
result:
ok 1 number(s): "434138343"
Test #17:
score: 0
Accepted
time: 184ms
memory: 224736kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
70334815
result:
ok 1 number(s): "70334815"
Test #18:
score: 0
Accepted
time: 202ms
memory: 224852kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
26692788
result:
ok 1 number(s): "26692788"
Test #19:
score: 0
Accepted
time: 194ms
memory: 224848kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
513359183
result:
ok 1 number(s): "513359183"
Test #20:
score: 0
Accepted
time: 180ms
memory: 224768kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
144382583
result:
ok 1 number(s): "144382583"
Test #21:
score: 0
Accepted
time: 1ms
memory: 9900kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 0
Accepted
time: 0ms
memory: 9972kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #23:
score: 0
Accepted
time: 0ms
memory: 9688kb
input:
2 10 01
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 207ms
memory: 224828kb
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: 206ms
memory: 224576kb
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: 149ms
memory: 224784kb
input:
3000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1
result:
ok 1 number(s): "1"
Test #27:
score: 0
Accepted
time: 132ms
memory: 224860kb
input:
3000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1
result:
ok 1 number(s): "1"
Extra Test:
score: 0
Extra Test Passed