QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#115022 | #5810. Doubly-sorted Grid | zhouhuanyi | 0 | 5736ms | 43332kb | C++11 | 1.8kb | 2023-06-24 14:20:00 | 2023-06-24 14:20:03 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 26
#define M 184756
#define K 20
#define mod 10007
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
int T,n,m,length,l[N+1][N+1],r[N+1][N+1],dp[N+1][M+1],DP[N+1][M+1],tong[M+1],num[1<<K];
char c[N+1][N+1];
int main()
{
int res;
bool op;
T=read();
while (T--)
{
n=read(),m=read(),length=0;
for (int i=0;i<(1<<(n+m));++i)
if (__builtin_popcount(i)==m)
tong[++length]=i,num[i]=length;
for (int i=0;i<=26;++i)
{
for (int j=0;j<=n+m;++j) l[i][j]=0,r[i][j]=j;
for (int j=1;j<=length;++j) dp[i][j]=0;
}
for (int i=1;i<=n;++i)
for (int j=1;j<=m;++j)
{
cin>>c[i][j];
if (c[i][j]!='.')
{
r[c[i][j]-'a'][n-i+j]=min(r[c[i][j]-'a'][n-i+j],j-1);
if (c[i][j]!='z') l[c[i][j]-'a'+1][n-i+j]=max(l[c[i][j]-'a'+1][n-i+j],j);
}
}
dp[0][length]=1;
for (int i=1;i<=26;++i)
{
for (int j=1;j<=n+m;++j)
for (int k=1;k<=length;++k)
DP[j][k]=0;
for (int j=1;j<=length;++j) DP[1][j]=dp[i-1][j];
for (int j=2;j<=n+m;++j)
for (int k=1;k<=length;++k)
{
Adder(DP[j][k],DP[j-1][k]);
if (tong[k]&(1<<(j-1)))
{
for (int t=j-1;t>=1;--t)
{
if (!(tong[k]&(1<<(t-1)))) Adder(DP[j][num[tong[k]^(1<<(j-1))^(1<<(t-1))]],DP[j-1][k]);
else break;
}
}
}
for (int j=1;j<=length;++j)
{
res=0,op=1;
for (int k=1;k<=n+m;++k)
{
res+=((tong[j]>>(k-1))&1);
if (res<l[i][k]||res>r[i][k]) op=0;
}
if (op) dp[i][j]=DP[n+m][j];
}
}
printf("%d\n",dp[26][1]);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 30220kb
input:
40 4 4 .... .... .... .... 4 4 abcd bcde cdef defg 4 4 bbcc ccde cdef deef 4 4 .... .... .r.. ..e. 3 4 .... .... ...g 1 3 f.. 2 2 .b bb 2 3 ... ..f 4 4 .... .... ..t. ..d. 3 3 .gn ... ... 4 4 ...a ...b ...c ...d 4 4 ...b ..bb .bbb bbbb 4 4 a... .b.. ..c. ...d 3 3 c.. glw ..w 1 4 .... 1 3 d.v 4 2 .. ...
output:
7285 1 1 0 718 231 2 686 0 3500 330 14 4096 2756 3737 19 8175 3737 7279 256 23 7569 5 6 1193 3621 3737 533 5154 120 26 5131 9875 0 5 6434 3420 0 2601 143
result:
wrong answer 1st lines differ - expected: 'Case #1: 7285', found: '7285'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 5736ms
memory: 43332kb
input:
40 5 10 .......... .......... .......... .......... .......... 10 10 ....a..... ....c..... ....g..... ....j..... ....l..... ....m..... ....n..... ....q..... ....t..... ....v..... 10 10 .......... .......... .......... .......... .......... .......... .......... .......... ...ok..... .......... 9 10 ...
output:
8791 7220 0 2510 4299 1663 981 1430 8814 2877 2124 0 4311 4458 8699 3727 14 5478 7922 6789 1252 132 3634 2275 9339 5249 8470 6236 421 8791 7836 1 8156 4861 7556 0 6161 3239 1 1
result:
wrong answer 1st lines differ - expected: 'Case #1: 8791', found: '8791'