QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#32028#1185. To argue, or not to argueWu_RenAC ✓134ms6260kbC++141.6kb2022-05-16 08:33:572022-05-16 08:33:59

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-16 08:33:59]
  • Judged
  • Verdict: AC
  • Time: 134ms
  • Memory: 6260kb
  • [2022-05-16 08:33:57]
  • Submitted

answer

#include <bits/stdc++.h>
const int mod=1e9+7;
using namespace std;
int n,m,K,f[2][4096][73],p=0,o=1,C[150][150],fac[150],_k[150];
char a[144][144],b[144][144];
void qmo(int &x){
	x+=(x>>31)&mod;
}
void init(int N){
	for(int i=0;i<=N;i++) for(int j=C[i][0]=1;j<=i;j++) qmo(C[i][j]=C[i-1][j]+C[i-1][j-1]-mod);
	for(int i=fac[0]=1;i<=N;i++) fac[i]=1ll*i*fac[i-1]%mod;
	for(int i=_k[0]=1;i<=N;i++) qmo(_k[i]=_k[i-1]+_k[i-1]-mod);
}
void sol(){
	scanf("%d%d%d",&n,&m,&K);
	for(int i=0;i<n;i++) scanf("%s",a[i]);
	if(n<m){
		for(int i=0;i<n;i++) for(int j=0;j<m;j++) b[j][i]=a[i][j];
		swap(a,b),swap(n,m);
	}
	int cnt=0;
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) cnt+=a[i][j]=='.';
	for(int S=0;S<(1<<m);S++) for(int j=0;j<=K;j++) f[0][S][j]=0;
	f[0][0][0]=1,p=0,o=1;
	for(int i=0;i<n;i++) for(int j=0;j<m;j++){
		for(int S=0;S<(1<<m);S++) for(int j=0;j<=K;j++) f[o][S][j]=0;
		for(int S=0;S<(1<<m);S++) if(a[i][j]=='.'||!((S>>j)&1)){
			if((S>>j)&1) for(int k=0;k<K;k++) qmo(f[o][S^(1<<j)][k+1]+=f[p][S][k]-mod);
			else{
				for(int k=0;k<=K;k++) qmo(f[o][S][k]+=f[p][S][k]-mod);
				if(a[i][j]=='.') for(int k=0;k<=K;k++) qmo(f[o][S^(1<<j)][k]+=f[p][S][k]-mod);
				if(a[i][j]=='.'&&j&&((S>>(j-1))&1)){
					for(int k=0;k<K;k++) qmo(f[o][S^(1<<(j-1))][k+1]+=f[p][S][k]-mod);
				}
			}
		}
		o^=1,p^=1;
	}
	int res=0;
	for(int j=0;j<=K;j++){
		int w=1ll*C[cnt-2*j][2*(K-j)]*fac[2*(K-j)]%mod*C[K][j]%mod*fac[j]%mod*f[p][0][j]%mod*_k[j]%mod;
		if(j&1) qmo(res-=w);
		else qmo(res+=w-mod);
	}
	printf("%d\n",res);
}
int main(){
	init(144);
	int T;
	scanf("%d",&T);
	while(T--) sol();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3828kb

input:

2
2 2 2
..
..
4 4 3
X.X.
....
.X..
...X

output:

8
347040

result:

ok 2 number(s): "8 347040"

Test #2:

score: 0
Accepted
time: 134ms
memory: 6260kb

input:

96
1 144 8
................................................................................................................................................
144 1 31
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
....

output:

517668733
268886110
64664470
926220403
0
0
372341012
839870997
115795952
169129272
928175112
399452284
981581814
563968454
82030165
770277954
161484719
374884294
988612558
269599606
838995341
614914000
779550646
19224822
195892020
368899964
857064056
437999888
225342223
836336621
981420655
30328633
...

result:

ok 96 numbers