QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#232343#7648. 网格图最大流计数grass8cow30 932ms26332kbC++142.9kb2023-10-30 11:13:462023-10-30 11:13:47

Judging History

你现在查看的是最新测评结果

  • [2023-10-30 11:13:47]
  • 评测
  • 测评结果:30
  • 用时:932ms
  • 内存:26332kb
  • [2023-10-30 11:13:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int qpow(int a,int b){
	int c=1;for(;b;b>>=1){
		if(b&1)c=1ll*a*c%mod;
		a=1ll*a*a%mod;
	}
	return c;
}
int head[320100],to[1010000],cur[320010],nxt[1010000],flow[1010000],cn=1;
void ad(int u,int v){
	to[++cn]=v,flow[cn]=1,nxt[cn]=head[u],head[u]=cn;
	to[++cn]=u,flow[cn]=0,nxt[cn]=head[v],head[v]=cn;
}
int S,T,d[320010];
bool bfs(){
	for(int i=1;i<=T;i++)cur[i]=head[i],d[i]=0;d[S]=1;queue<int>q;q.push(S);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=head[u];i;i=nxt[i])if(flow[i]&&!d[to[i]])
		d[to[i]]=d[u]+1,q.push(to[i]);
	}
	return d[T]>0;
}
int dfs(int s,int in){
	if(s==T)return in;int out=0;
	for(int &i=cur[s];i&&in;i=nxt[i])if(flow[i]&&d[to[i]]==d[s]+1){
		int p=dfs(to[i],min(in,flow[i]));
		flow[i]-=p,flow[i^1]+=p,in-=p,out+=p;
	}
	if(!out)d[s]=0;return out;
}
int n,dp[510][510],e[510][510],Z[510][510];
int ip(int o,int x,int y){return o*n*n+(x-1)*n+y;}
char c[510];
int t1,t2,X[510],Y[510],sum;
namespace Sub1{
	int dp[1<<18],dp2[1<<18],pp[1<<18];
	void sol(){
		memset(dp,0,sizeof(dp));
		for(int i=1;i<(1<<t1);i++)pp[i]=pp[i>>1]+(i&1);
		dp[0]=1;
		for(int i=1;i<=t2;i++){
			for(int s=0;s<(1<<t1);s++)dp2[s]=0;
			for(int s=0;s<(1<<t1);s++){
				int fp=1;
				for(int j=t1-1;j>=0;j--){
					if(!((s>>j)&1))
					(dp2[s|(1<<j)]+=1ll*dp[s]*fp%mod*Z[X[j+1]][Y[i]]%mod)%=mod;
					else fp=-fp;
				}
				(dp2[s]+=dp[s])%=mod;
			}
			for(int s=0;s<(1<<t1);s++)dp[s]=dp2[s];
		}
		int ans=0;
		for(int s=0;s<(1<<t1);s++)if(pp[s]==sum)(ans+=dp[s])%=mod;
		printf("%d\n",(ans+mod)%mod);
	}
}
int f[510][510];
int main(){
	scanf("%d%d%d",&t1,&t2,&n);
	S=n*n*2+1,T=n*n*2+2;
	for(int i=1;i<=t1;i++)scanf("%d",&X[i]),ad(S,ip(0,1,X[i]));
	for(int i=1;i<=t2;i++)scanf("%d",&Y[i]),ad(ip(1,n,Y[i]),T);
	for(int i=1;i<=n;i++){
		scanf("%s",c+1);for(int j=1;j<=n;j++){
			e[i][j]=c[j]-'0';
			if(e[i][j])ad(ip(0,i,j),ip(1,i,j));
			if(i<n)ad(ip(1,i,j),ip(0,i+1,j));
			if(j<n)ad(ip(1,i,j),ip(0,i,j+1));
		}
	}
	while(bfs())sum+=dfs(S,1e9);
	printf("%d ",sum);
	for(int i=1;i<=n;i++){
		memset(dp,0,sizeof(dp));
		for(int j=1;j<=n;j++)for(int k=1;k<=n;k++){
			dp[j][k]=(dp[j-1][k]+dp[j][k-1])%mod;
			if(j==1&&i==k)dp[j][k]++;
			if(e[j][k]==0)dp[j][k]=0;
		}
		for(int j=i;j<=n;j++)Z[i][j]=dp[n][j];
	}
	if(t1<=10||t1<=18&&t2<=18){Sub1::sol();return 0;}
	for(int i=1;i<=t1;i++)for(int j=1;j<=t2;j++)f[i][j]=Z[X[i]][Y[j]];
	n=t1;
	int ans=1;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++)if(f[j][i]){
			for(int z=1;z<=n;z++)swap(f[i][z],f[j][z]);
			ans=-ans;break;
		}
		if(!f[i][i]){ans=0;break;}
		int I=qpow(f[i][i],mod-2);
		for(int j=1;j<=n;j++)if(i!=j){
			int z=1ll*f[j][i]*I%mod;
			for(int k=1;k<=n;k++)(f[j][k]-=1ll*z*f[i][k]%mod)%=mod;
		}
	}
	for(int i=1;i<=n;i++)ans=1ll*ans*f[i][i]%mod;
	return printf("%d",(ans%mod+mod)%mod),0;
} 

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 3ms
memory: 15932kb

input:

7 7 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1111111
1111111
1111111
1111111
1111111
1111111
1111111

output:

7 1

result:

ok 2 number(s): "7 1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 17976kb

input:

7 7 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1111111
1111111
1111111
1111111
1111111
1111111
1111111

output:

7 1

result:

ok 2 number(s): "7 1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 18056kb

input:

7 7 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1111111
1111111
1111111
1111111
1111111
1111111
1111111

output:

7 1

result:

ok 2 number(s): "7 1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 17940kb

input:

7 7 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1111111
1111111
1111111
1111111
1111111
1110111
1111111

output:

6 52

result:

ok 2 number(s): "6 52"

Test #5:

score: 0
Accepted
time: 2ms
memory: 15968kb

input:

7 7 7
1 2 3 4 5 6 7
1 2 3 4 5 6 7
1111111
1111111
1111111
1111111
1111111
1110111
1111111

output:

6 52

result:

ok 2 number(s): "6 52"

Subtask #2:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 5
Accepted
time: 67ms
memory: 18224kb

input:

16 17 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
111111111111111111
111111111111111111
111011111111111111
111111111111111111
111111111111111111
111011110111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
1...

output:

14 328354990

result:

ok 2 number(s): "14 328354990"

Test #7:

score: 0
Accepted
time: 128ms
memory: 16392kb

input:

17 16 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111101111111111
111111111111111111
111111111111011111
...

output:

15 449998848

result:

ok 2 number(s): "15 449998848"

Test #8:

score: 0
Accepted
time: 71ms
memory: 16272kb

input:

16 18 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
111111111111110111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111110111111
111111111111111111
11111111111111111...

output:

15 844316215

result:

ok 2 number(s): "15 844316215"

Test #9:

score: 0
Accepted
time: 63ms
memory: 16500kb

input:

16 17 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
111111111111111111
111111111111111111
111011111111110111
111111111111111111
111111111111111111
111011111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
1...

output:

15 133840

result:

ok 2 number(s): "15 133840"

Test #10:

score: 0
Accepted
time: 292ms
memory: 17276kb

input:

18 18 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111111111111
111111111011111111
111111111111111111
111101111111111111
111111111111111111
11111111111...

output:

16 27330297

result:

ok 2 number(s): "16 27330297"

Subtask #3:

score: 10
Accepted

Dependency #2:

100%
Accepted

Test #11:

score: 10
Accepted
time: 357ms
memory: 24012kb

input:

10 377 400
1 2 3 4 5 6 7 8 9 10
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

10 843273461

result:

ok 2 number(s): "10 843273461"

Test #12:

score: 0
Accepted
time: 345ms
memory: 23448kb

input:

10 367 400
1 2 3 4 5 6 7 8 9 10
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104...

output:

10 273577493

result:

ok 2 number(s): "10 273577493"

Test #13:

score: 0
Accepted
time: 358ms
memory: 23616kb

input:

10 350 400
1 2 3 4 5 6 7 8 9 10
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 11...

output:

9 605707862

result:

ok 2 number(s): "9 605707862"

Test #14:

score: 0
Accepted
time: 364ms
memory: 24960kb

input:

10 375 400
1 2 3 4 5 6 7 8 9 10
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...

output:

10 213051017

result:

ok 2 number(s): "10 213051017"

Test #15:

score: 0
Accepted
time: 357ms
memory: 24820kb

input:

10 330 400
1 2 3 4 5 6 7 8 9 10
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 ...

output:

9 320097125

result:

ok 2 number(s): "9 320097125"

Test #16:

score: 0
Accepted
time: 370ms
memory: 25040kb

input:

10 360 400
1 2 3 4 5 6 7 8 9 10
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107...

output:

10 195548453

result:

ok 2 number(s): "10 195548453"

Test #17:

score: 0
Accepted
time: 369ms
memory: 24752kb

input:

10 365 400
1 2 3 4 5 6 7 8 9 10
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 10...

output:

10 20617593

result:

ok 2 number(s): "10 20617593"

Test #18:

score: 0
Accepted
time: 390ms
memory: 23432kb

input:

10 334 400
1 2 3 4 5 6 7 8 9 10
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 11...

output:

10 602177426

result:

ok 2 number(s): "10 602177426"

Test #19:

score: 0
Accepted
time: 378ms
memory: 24128kb

input:

10 323 400
1 2 3 4 5 6 7 8 9 10
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 1...

output:

9 619229914

result:

ok 2 number(s): "9 619229914"

Test #20:

score: 0
Accepted
time: 373ms
memory: 24936kb

input:

10 379 400
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1...

output:

10 409116219

result:

ok 2 number(s): "10 409116219"

Subtask #4:

score: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #21:

score: 0
Wrong Answer
time: 822ms
memory: 24176kb

input:

100 322 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

85 0

result:

wrong answer 2nd numbers differ - expected: '207066474', found: '0'

Subtask #5:

score: 10
Accepted

Test #31:

score: 10
Accepted
time: 932ms
memory: 23996kb

input:

73 73 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 ...

output:

73 849796347

result:

ok 2 number(s): "73 849796347"

Test #32:

score: 0
Accepted
time: 827ms
memory: 23676kb

input:

68 68 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152...

output:

68 334069950

result:

ok 2 number(s): "68 334069950"

Test #33:

score: 0
Accepted
time: 881ms
memory: 23716kb

input:

72 72 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133...

output:

72 180096245

result:

ok 2 number(s): "72 180096245"

Test #34:

score: 0
Accepted
time: 883ms
memory: 23364kb

input:

71 71 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 13...

output:

71 234343448

result:

ok 2 number(s): "71 234343448"

Test #35:

score: 0
Accepted
time: 834ms
memory: 26256kb

input:

68 68 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152...

output:

68 371509898

result:

ok 2 number(s): "68 371509898"

Test #36:

score: 0
Accepted
time: 875ms
memory: 26284kb

input:

200 200 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

200 852372194

result:

ok 2 number(s): "200 852372194"

Test #37:

score: 0
Accepted
time: 856ms
memory: 24124kb

input:

230 230 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

230 65874836

result:

ok 2 number(s): "230 65874836"

Test #38:

score: 0
Accepted
time: 842ms
memory: 23196kb

input:

260 260 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

260 272563656

result:

ok 2 number(s): "260 272563656"

Test #39:

score: 0
Accepted
time: 847ms
memory: 23976kb

input:

290 290 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

290 95450701

result:

ok 2 number(s): "290 95450701"

Test #40:

score: 0
Accepted
time: 839ms
memory: 26332kb

input:

320 320 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

320 266455174

result:

ok 2 number(s): "320 266455174"

Subtask #6:

score: 0
Wrong Answer

Dependency #5:

100%
Accepted

Test #41:

score: 0
Wrong Answer
time: 467ms
memory: 23644kb

input:

107 371 400
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

107 818209365

result:

wrong answer 2nd numbers differ - expected: '3979643', found: '818209365'

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

0%