QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#491534 | #8552. Sticks | ucup-team2307# | AC ✓ | 1025ms | 340488kb | C++23 | 2.4kb | 2024-07-25 20:07:14 | 2024-07-25 20:07:15 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
typedef long long ll;
#define int ll
using namespace std;
const int mod = 998244353;
string s[3030];
int a[3030][3030];
int dp[3030][3030];
vector<int> zs1[3030], zs2[3030], os1[3030], os2[3030];
void calc(int n, int m)
{
// if (n==1 && m==1)
// {
// dp[n][m] = (a[n][m] == -1) + 1;
// return;
// }
int ans = 0;
if (a[n][m] != 0)
{
if (zs1[n][1] > m) ans += dp[n-1][m];
if (zs2[m][1] > n) ans += dp[n][m-1];
if (zs1[n][1] > m && zs2[m][1] > n)
ans -= dp[n-1][m-1];
// cout<<n<<" "<<m<<" -> "<<ans<<"\n";
}
if (a[n][m] != 1)
{
int r1 = min(m-1, zs1[n][1]-1);
auto it1 = upper_bound(os1[n].begin(), os1[n].end(), r1);
int l1 = *prev(it1);
if (*it1 <= m) l1 = r1+1;
ans += (r1-l1+1)*dp[n-1][m];
// cout<<n<<" "<<m<<" -> "<<ans<<"\n";
int r2 = min(n-1, zs2[m][1]-1);
auto it2 = upper_bound(os2[m].begin(), os2[m].end(), r2);
int l2 = *prev(it2);
if (*it2 <= n) l2 = r2+1;
ans += (r2-l2+1)*dp[n][m-1];
// cout<<n<<" "<<m<<" -> "<<ans<<"\n";
ans -= (r2-l2+1)*(r1-l1+1)*dp[n-1][m-1];
// cout<<n<<" "<<m<<" -> "<<ans<<"\n";
}
dp[n][m] = (ans%mod+mod)%mod;
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for (int i=0; i<n; i++)
cin>>s[i];
for (int i=1; i<=n; i++)
{
zs1[i].pb(0);
zs2[i].pb(0);
os1[i].pb(0);
os2[i].pb(0);
}
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j++)
{
a[i][j] = -1;
if (s[i-1][j-1] == '0')
zs1[i].pb(j), zs2[j].pb(i), a[i][j] = 0;
if (s[i-1][j-1] == '1')
os1[i].pb(j), os2[j].pb(i), a[i][j] = 1;
}
for (int i=1; i<=n; i++)
{
zs1[i].pb(n+1);
zs2[i].pb(n+1);
os1[i].pb(n+1);
os2[i].pb(n+1);
}
for (int i=0; i<=n; i++)
dp[0][i] = dp[i][0] = 1;
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j++)
calc(i, j);
// for (int i=1; i<=n; i++, cout<<"\n")
// for (int j=1; j<=n; j++)
// cout<<dp[i][j]<<" ";
cout<<dp[n][n]<<"\n";
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5856kb
input:
2 ?? ??
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5816kb
input:
5 ??1?? ?1??0 ??0?? ???1? ??1??
output:
3144
result:
ok 1 number(s): "3144"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5848kb
input:
10 0000000000 ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ?????????? ??????????
output:
361458985
result:
ok 1 number(s): "361458985"
Test #4:
score: 0
Accepted
time: 142ms
memory: 159736kb
input:
3000 ??????????????????????????????????????????????????????????0?????????????????????0??????????????????????????????????????????????????????????????????????????????????????0???????????????????????????????????????????0???????????????????????????????????????????????????????????????????????????????????...
output:
56427841
result:
ok 1 number(s): "56427841"
Test #5:
score: 0
Accepted
time: 144ms
memory: 157564kb
input:
3000 ????????????????????????????????????????0??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
145247225
result:
ok 1 number(s): "145247225"
Test #6:
score: 0
Accepted
time: 119ms
memory: 157236kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
925248762
result:
ok 1 number(s): "925248762"
Test #7:
score: 0
Accepted
time: 111ms
memory: 156844kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
845505610
result:
ok 1 number(s): "845505610"
Test #8:
score: 0
Accepted
time: 109ms
memory: 156864kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
123028256
result:
ok 1 number(s): "123028256"
Test #9:
score: 0
Accepted
time: 350ms
memory: 160140kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????1???1??????????????????????????????????????????????????????????????????????1????????????????????????????????????????????????????????????????...
output:
242286033
result:
ok 1 number(s): "242286033"
Test #10:
score: 0
Accepted
time: 200ms
memory: 157972kb
input:
3000 ??????????????????????????1????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
448817936
result:
ok 1 number(s): "448817936"
Test #11:
score: 0
Accepted
time: 134ms
memory: 157600kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
621258555
result:
ok 1 number(s): "621258555"
Test #12:
score: 0
Accepted
time: 108ms
memory: 156876kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
552098298
result:
ok 1 number(s): "552098298"
Test #13:
score: 0
Accepted
time: 117ms
memory: 156780kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
190431651
result:
ok 1 number(s): "190431651"
Test #14:
score: 0
Accepted
time: 115ms
memory: 156896kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 108ms
memory: 157460kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
641634738
result:
ok 1 number(s): "641634738"
Test #16:
score: 0
Accepted
time: 124ms
memory: 157016kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
434138343
result:
ok 1 number(s): "434138343"
Test #17:
score: 0
Accepted
time: 121ms
memory: 157304kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
70334815
result:
ok 1 number(s): "70334815"
Test #18:
score: 0
Accepted
time: 109ms
memory: 157140kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
26692788
result:
ok 1 number(s): "26692788"
Test #19:
score: 0
Accepted
time: 118ms
memory: 156784kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
513359183
result:
ok 1 number(s): "513359183"
Test #20:
score: 0
Accepted
time: 117ms
memory: 157532kb
input:
3000 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...
output:
144382583
result:
ok 1 number(s): "144382583"
Test #21:
score: 0
Accepted
time: 1ms
memory: 5800kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 0
Accepted
time: 1ms
memory: 5712kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #23:
score: 0
Accepted
time: 1ms
memory: 5872kb
input:
2 10 01
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 1017ms
memory: 255844kb
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: 1025ms
memory: 256100kb
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: 758ms
memory: 340364kb
input:
3000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1
result:
ok 1 number(s): "1"
Test #27:
score: 0
Accepted
time: 764ms
memory: 340488kb
input:
3000 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1
result:
ok 1 number(s): "1"
Extra Test:
score: 0
Extra Test Passed