QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#115514 | #5810. Doubly-sorted Grid | lyx123886a123886 | 0 | 14104ms | 98508kb | C++14 | 2.7kb | 2023-06-26 10:54:12 | 2023-06-26 10:54:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int read() {
char ch=getchar();int res=0,fl=1;
while(ch<'0'||ch>'9'){if(ch=='-') fl=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
return res*fl;
}
const int N=10;
const int M=184756;
const int mod=10007;
const int inf=1000000000;
int n,m;
int dp[1<<(N+N)],f[N+N][1<<(N+N)],__total,a[M],up[1<<(N+N)],down[1<<(N+N)];
void calc(int now) {
for(int idx=0;idx<__total;++idx) {
int s=a[idx];
f[0][s]=dp[s];
for(int k=1;k<n+m;++k) {
f[k][s]=f[k-1][s];
if((s&(1<<k))&&!(s&(1<<(k-1)))) {
(f[k][s]+=f[k+((s>>(k+1))&1)][s^(3<<(k-1))])%=mod;
// if(now==4&&s==12) printf("(%d,%d) ",s^(3<<(k-1)),f[k+((s>>(k+1))&1)][s^(3<<(k-1))]);//注意,如果下一位是1,011->101产生新下凸,这个下凸要越过
}
}
// if(now==4&&s==12) printf("*\n*\n");
dp[s]=(up[s]<=now&&down[s]>now)*f[n+m-1][s];
}
return ;
}
int e[N][N];
string tmp;
void print(int s) {
printf("(");
for(int i=0;i<n+m;++i) printf("%d ",(s>>i)&1);
printf(")");
return ;
}
void gen() {
cin>>n>>m;
for(int i=0;i<n;++i) {
cin>>tmp;
for(int j=0;j<m;++j) e[i][j]=(tmp[j]=='.')?0:(tmp[j]-'a'+1);
}
memset(up,0,sizeof(up));
memset(down,60,sizeof(down));
__total=0;
for(int s=0;s<(1<<(n+m));++s) {
if(__builtin_popcount(s)!=n) continue;
a[__total++]=s;
}
for(int idx=0;idx<__total;++idx) {
int s=a[idx];
for(int i=0;i<n+m-1;++i)
if(!(s&(1<<i))&&(s&(1<<(i+1)))) {
int x,y,j;
for(x=n,y=0,j=0;j<=i;++j) //n!!
if(s&(1<<j)) x--;
else y++;
y--;x--;
up[s]=max(up[s^(3<<i)],(e[x][y]>0)?e[x][y]:0);
//if(s==5) printf("(%d,%d)\n",x,y);
break;
}
}
for(int idx=__total-1;idx>=0;--idx) {
int s=a[idx];
for(int i=0;i<n+m-1;++i)
if((s&(1<<i))&&!(s&(1<<(i+1)))) {
int x,y,j;
for(x=n,y=0,j=0;j<=i;++j) //n!!
if(s&(1<<j)) x--;
else y++;
//y++;x++;不动了,这就是左上角!!
down[s]=min(down[s^(3<<i)],(e[x][y]>0)?e[x][y]:inf);
break;
}
}
memset(dp,0,sizeof(dp));
dp[(1<<n)-1]=1;
for(int i=1;i<=26;++i) {
calc(i);
/* for(int idx=0;idx<__total;++idx) {
print(a[idx]);printf(" %d\n",dp[a[idx]]);
for(int k=0;k<n+m;++k) printf("%d,",f[k][a[idx]]);
printf("\n\n");
}
printf("\n\n\n\n");*/
}
printf("%d\n",dp[((1<<n)-1)<<m]);
/* for(int i=0;i<n;++i) {
for(int j=0;j<m;++j) printf("%d",e[i][j]);
printf("\n");
}
for(int idx=0;idx<__total;++idx) {
print(a[idx]);
printf("(%d,%d)\n",up[a[idx]],down[a[idx]]);
}*/
return ;
}
int main()
{
//freopen("qoj5810.in","r",stdin);
//freopen("qoj5810.out","w",stdout);
int T;
cin>>T;
while(T--)
gen();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 18ms
memory: 32996kb
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: 14104ms
memory: 98508kb
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'