QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#115226 | #5810. Doubly-sorted Grid | Zesty_Fox | 30 ✓ | 4969ms | 69788kb | C++20 | 2.1kb | 2023-06-25 10:08:19 | 2023-06-25 10:08:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using u32=unsigned int;
using i64=long long;
using u64=unsigned long long;
using db=double;
using vi=vector<int>;
using pii=pair<int,int>;
template<typename T>
T read(){
T x=0,f=0;char ch=getchar();
while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
while(isdigit(ch)) x=x*10+(ch-'0'),ch=getchar();
return f?-x:x;
}
#define rdi read<int>
#define rdi64 read<i64>
#define fi first
#define se second
#define pb push_back
const int N=10,N2=N*2,S=2e5+10,C=26,MOD=10007;
int popc[(1<<N2)|10],kth[(1<<N2)|10][N];
void init(int mx){
popc[0]=0;
for(int i=1;i<(1<<mx);i++){
popc[i]=popc[i>>1]+(i&1);
kth[i][0]=__builtin_ctz(i);
for(int j=1;j<min(popc[i],N);j++)
kth[i][j]=kth[i&(i-1)][j-1];
}
}
template<typename T>
void inc(T &a,T b){
if((a+=b)>=MOD) a-=MOD;
}
int n,m;
char a[N][N2];
int f[2][N][S],id[(1<<N2)|10];
void solve(int tid){
n=rdi(),m=rdi();
for(int i=0;i<n;i++)
scanf("%s",a[i]);
vi st;
for(int i=0;i<(1<<(n+m));i++)
if(popc[i]==n) id[i]=st.size(),st.pb(i);
memset(f,0,sizeof(f));
f[0][0][id[((1<<n)-1)<<m]]=1;
for(int i=0,nw=0;i<C;i++,nw^=1){
for(int j=0;j<n;j++){
for(int u=0;u<st.size();u++){
int s=st[u],v=f[nw][j][u]%MOD;
if(!v) continue;
int p=kth[s][j],mi=(j?kth[s][j-1]+1:0);
for(int k=p,fl=1;k>=mi&&fl;k--){
int n_s=id[s^(1<<p)^(1<<k)];
if(j!=n-1) f[nw][j+1][n_s]+=v;
else f[nw^1][0][n_s]+=v;
char ch=a[j][m-(k-j)];
fl&=(ch=='.'||ch==i+'a');
}
f[nw][j][u]=0;
}
}
}
int ans=f[C&1][0][id[(1<<n)-1]]%MOD;
printf("Case #%d: %d\n",tid,ans);
}
int main(){
#ifdef LOCAL
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
#endif
init(N2);
int T=rdi();
for(int i=1;i<=T;i++) solve(i);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 25ms
memory: 65432kb
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:
Case #1: 7285 Case #2: 1 Case #3: 1 Case #4: 0 Case #5: 718 Case #6: 231 Case #7: 2 Case #8: 686 Case #9: 0 Case #10: 3500 Case #11: 330 Case #12: 14 Case #13: 4096 Case #14: 2756 Case #15: 3737 Case #16: 19 Case #17: 8175 Case #18: 3737 Case #19: 7279 Case #20: 256 Case #21: 23 Case #22: 7569 Case ...
result:
ok 40 lines
Subtask #2:
score: 20
Accepted
Test #2:
score: 20
Accepted
time: 4969ms
memory: 69788kb
input:
40 5 10 .......... .......... .......... .......... .......... 10 10 ....a..... ....c..... ....g..... ....j..... ....l..... ....m..... ....n..... ....q..... ....t..... ....v..... 10 10 .......... .......... .......... .......... .......... .......... .......... .......... ...ok..... .......... 9 10 ...
output:
Case #1: 8791 Case #2: 7220 Case #3: 0 Case #4: 2510 Case #5: 4299 Case #6: 1663 Case #7: 981 Case #8: 1430 Case #9: 8814 Case #10: 2877 Case #11: 2124 Case #12: 0 Case #13: 4311 Case #14: 4458 Case #15: 8699 Case #16: 3727 Case #17: 14 Case #18: 5478 Case #19: 7922 Case #20: 6789 Case #21: 1252 Cas...
result:
ok 40 lines
Extra Test:
score: 0
Extra Test Passed