QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#65945#1185. To argue, or not to argueeyiigjknAC ✓244ms6348kbC++141.8kb2022-12-04 14:59:412022-12-04 14:59:45

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-12-04 14:59:45]
  • Judged
  • Verdict: AC
  • Time: 244ms
  • Memory: 6348kb
  • [2022-12-04 14:59:41]
  • Submitted

answer

# include <bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int N=144,mod=1e9+7;
int pw2[150],fac[150],finv[150],f[2][80][5010];
char s[150][150];
inline int add(int x,int y){return (x+=y)<mod?x:x-mod;}
inline void upd(int &x,const int &y){if((x+=y)>=mod) x-=mod;}
inline void upd(int &x,const ll &y){x=(x+y)%mod;}
inline int P(int n,int m){return (ll)fac[n]*finv[n-m]%mod;}
int power(int a,int b)
{
	int ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1) ans=(ll)ans*a%mod;
	return ans;
}
int main()
{
	int T,n,m,K;
	pw2[0]=fac[0]=fac[1]=1;
	for(int i=1;i<=N;i++) pw2[i]=add(pw2[i-1],pw2[i-1]);
	for(int i=2;i<=N;i++) fac[i]=(ll)fac[i-1]*i%mod;
	finv[N]=power(fac[N],mod-2);
	for(int i=N-1;i>=0;i--) finv[i]=(ll)finv[i+1]*(i+1)%mod;
	cin>>T;
	while(T--)
	{
		scanf("%d%d%d",&n,&m,&K);
		for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
		if(n<m)
		{
			for(int i=1;i<=n;i++)
				for(int j=i+1;j<=m;j++)
					swap(s[i][j],s[j][i]);
			swap(n,m);
		}
		int cnt=0,cur=0,ans=0;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				cnt+=(s[i][j]=='.');
		f[cur][0][0]=1;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
			{
				cur^=1;
				for(int k=0;k<=K;k++)
					for(int l=0;l<(1<<m);l++)
					{
						int &x=f[cur^1][k][l];
						if(!x) continue;
						if(s[i][j]=='X') upd(f[cur][k][l&~(1<<j-1)],x);
						else
						{
							upd(f[cur][k][l|(1<<j-1)],x);
							if(k<K && j>1 && (l>>j-2)&1) upd(f[cur][k+1][l&~(3<<j-2)],x);
							if(k<K && (l>>j-1)&1) upd(f[cur][k+1][l&~(1<<j-1)],x);
						}
						x=0;
					}
			}
		for(int i=0;i<=K;i++)
			for(int j=0;j<(1<<m);j++)
			{
				int &x=f[cur][i][j];
				upd(ans,(ll)x*(i&1?mod-pw2[i]:pw2[i])%mod*P(K,i)%mod*P(cnt-2*i,2*(K-i)));
				x=0;
			}
		printf("%d\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3632kb

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: 244ms
memory: 6348kb

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