QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408400#7648. 网格图最大流计数qwqwf15 871ms16928kbC++145.5kb2024-05-10 09:58:252024-05-10 09:58:27

Judging History

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

  • [2024-05-10 09:58:27]
  • 评测
  • 测评结果:15
  • 用时:871ms
  • 内存:16928kb
  • [2024-05-10 09:58:25]
  • 提交

answer

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
//#pragma GCC optimize("Ofast","unroll-loops","inline")
#include<bits/stdc++.h>
#define ll long long
//#define int ll
#define pb push_back
using namespace std;
const int N=1e3+10,mod=1e9+7;
const int inv2=(mod+1)/2;
inline void Add(int &x,int y){x+=y;if(x>=mod) x-=mod;}
inline void Del(int &x,int y){x-=y;if(x<0) x+=mod;}
inline int del(int x,int y){x-=y;return x<0?x+mod:x;}
inline int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
inline int iep(int x){return x&1?mod-1:1;}
int qpow(int a,int b){
	int res=1;
	while(b){
		if(b&1) res=1ll*res*a%mod;
		a=1ll*a*a%mod;b>>=1;
	}return res;
}
struct Faction{
	int len;vector<int> v;
	inline void init(int l){len=l;v.resize(l+1);}
};
namespace Poly{
	inline Faction operator >>(Faction f,int k){
		int len=f.len;f.init(len+k);
		for(int i=len;~i;i--) f.v[i+k]=f.v[i];
		for(int i=0;i<k;i++) f.v[i]=0;
		return f;
	}
	inline Faction operator <<(Faction f,int k){
		int len=f.len;
		for(int i=k;i<=len;i++) f.v[i-k]=f.v[i];
		for(int i=max(0,len-k+1);i<=len;i++) f.v[i]=0;
		f.init(max(0,len-k));
		return f;
	}
	inline Faction operator *(Faction a,int k){
		Faction c;c.init(a.len);
		for(int i=0;i<=a.len;i++) c.v[i]=1ll*a.v[i]*k%mod;
		return c;
	}
	inline Faction operator +(Faction a,Faction b){
		Faction c;int len=max(a.len,b.len);c.init(len);a.init(len);b.init(len);
		for(int i=0;i<=len;i++) c.v[i]=add(a.v[i],b.v[i]);
		return c;
	}
	inline Faction operator -(Faction a,Faction b){
		Faction c;int len=max(a.len,b.len);c.init(len);a.init(len);b.init(len);
		for(int i=0;i<=len;i++) c.v[i]=del(a.v[i],b.v[i]);
		return c;
	}
	void print(Faction x){
		for(int i=0;i<=x.len;i++) cout<<x.v[i]<<' ';cout<<'\n';
	}
	inline Faction rev(Faction &f){
		for(int i=0;i<=f.len;i++) f.v[i]=del(0,f.v[i]);
		return f;
	}
}
using namespace Poly;
void Print(int a[N][N],int n){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++) cout<<a[i][j]<<' ';cout<<'\n';
	}
}
Faction f[N];
Faction det(int a[N][N],int n){
	for(int i=2;i<=n;i++){
		if(!a[i][i-1]) for(int j=i+1;j<=n;j++) if(a[j][i-1]){swap(a[i],a[j]);for(int k=1;k<=n;k++) swap(a[k][i],a[k][j]);break;}
		if(a[i][i-1]){
			int inv=qpow(a[i][i-1],mod-2);
			for(int j=i+1;j<=n;j++){
				int res=1ll*a[j][i-1]*inv%mod;
				for(int k=i-1;k<=n;k++) Del(a[j][k],1ll*a[i][k]*res%mod);
				for(int k=1;k<=n;k++) Add(a[k][i],1ll*a[k][j]*res%mod);
			}
		}
	}
	f[0].init(0);f[0].v[0]=1;
	for(int i=1;i<=n;i++){
		f[i]=f[i-1]>>1;
		for(int j=i,w=1;j;w=1ll*w*a[j][j-1]%mod,j--){
			int res=1ll*a[j][i]*w%mod;f[i]=f[i]-(f[j-1]*res);
		}
	}
	return f[n];
}
Faction F;int cnt,D[N][N],E[N];
void solve(int a[N][N],int b[N][N],int c[N][N],int n){
	bool fl=0;
	for(int i=1;i<=n;i++){
		while(!a[i][i]){
			for(int j=i+1;j<=n;j++)if(a[i][j]){for(int k=1;k<=n;k++) swap(a[k][i],a[k][j]),swap(b[k][i],b[k][j]),swap(c[k][i],c[k][j]);fl^=1;break;}
			if(a[i][i]) break;
			for(int k=1;k<=n;k++) a[i][k]=b[i][k],b[i][k]=c[i][k],c[i][k]=0;
			cnt++;
			if(cnt>2*n) return ;
			for(int j=1;j<i;j++){
				int inv=qpow(a[j][j],mod-2),res=1ll*inv*a[i][j]%mod;
				for(int k=1;k<=n;k++) Del(a[i][k],1ll*res*a[j][k]%mod),Del(b[i][k],1ll*res*b[j][k]%mod),Del(c[i][k],1ll*res*c[j][k]%mod);
			}
		}
		int inv=qpow(a[i][i],mod-2);
		for(int j=1;j<=n;j++) if(j!=i){
			int res=1ll*inv*a[j][i]%mod;
			for(int k=1;k<=n;k++) Del(a[j][k],1ll*res*a[i][k]%mod),Del(b[j][k],1ll*res*b[i][k]%mod),Del(c[j][k],1ll*res*c[i][k]%mod);
		}
	}
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) b[i][j]=del(mod,b[i][j]);
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) c[i][j]=del(mod,c[i][j]);
	int res=1;
	for(int i=1;i<=n;i++){
		res=1ll*res*a[i][i]%mod;
		int inv=qpow(a[i][i],mod-2);
		for(int j=1;j<=n;j++) b[i][j]=1ll*b[i][j]*inv%mod,c[i][j]=1ll*c[i][j]*inv%mod;
		a[i][i]=1;
	}
	for(int i=1;i<=n;i++) for(int j=n+1;j<=n+n;j++) D[i][j]=(i==j-n);
	for(int i=n+1;i<=n+n;i++) for(int j=1;j<=n;j++) D[i][j]=c[i-n][j];
	for(int i=n+1;i<=n+n;i++) for(int j=n+1;j<=n+n;j++) D[i][j]=b[i-n][j-n];
	F=det(D,2*n);F=F*res;F=F<<cnt,F.init(min(F.len,2*n));
	if(fl) rev(F);
}
int n,m,k,a[N],b[N],dp[N][N],d[N][N],A[N][N],B[N][N],C[N][N],t[N][N],si[N],sj[N];
char ch[N][N];
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++) cin>>a[i]; 
	for(int i=1;i<=n;i++) cin>>b[i];
	for(int i=1;i<=k;i++) cin>>(ch[i]+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k;j++) for(int p=1;p<=k;p++) dp[j][p]=0;
		if(ch[1][a[i]]=='1') dp[1][a[i]]=1;
		for(int j=1;j<=k;j++) for(int p=1;p<=k;p++) if(dp[j][p]){
			if(ch[j+1][p]=='1') Add(dp[j+1][p],dp[j][p]);
			if(ch[j][p+1]=='1') Add(dp[j][p+1],dp[j][p]);
		}
		for(int j=1;j<=m;j++) d[i][j]=dp[k][b[j]];
	}
	d[++n][++m]=1;
	for(int i=1;i<n;i++) for(int j=i+1;j<=n;j++){
		for(int p=1;p<=m;p++) si[p]=d[i][p],sj[p]=d[j][p];
		int x=0,y=0,z=0;
		for(int p=m;p;p--){
			Add(z,del(1ll*si[p]*y%mod,1ll*sj[p]*x%mod));
			Add(x,si[p]),Add(y,sj[p]);
		}
		t[i][j]=z,t[j][i]=del(0,z);
	}
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=n;j++) cout<<t[i][j]<<' ';cout<<'\n'; 
//	}
	int nn=n;if(n&1) n++;
	for(int i=1;i<n;i++) for(int j=i+1;j<=n;j++){
		C[i][j]=iep(i+j+1);
		if(j<nn) A[i][j]=t[i][j];
		else if(j==nn) B[i][j]=t[i][j];
		C[j][i]=del(0,C[i][j]);B[j][i]=del(0,B[i][j]);A[j][i]=del(0,A[i][j]);
	}
	solve(A,B,C,n);
	int s=F.len;
	E[0]=1;
	for(int i=1;i<=s/2;i++){
		E[i]=F.v[i];
		for(int j=1;j<i;j++) Del(E[i],1ll*E[j]*E[i-j]%mod);
		E[i]=1ll*E[i]*inv2%mod; 
	}
	cout<<s/2<<' '<<E[s/2]<<'\n';
	return 0;
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 2ms
memory: 9892kb

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: 5
Accepted
time: 0ms
memory: 7820kb

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: 5
Accepted
time: 1ms
memory: 7900kb

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: 5
Accepted
time: 1ms
memory: 7832kb

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: 5
Accepted
time: 1ms
memory: 7832kb

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: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 6112kb

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:

1 222123896

result:

wrong answer 1st numbers differ - expected: '14', found: '1'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 10
Accepted

Test #31:

score: 10
Accepted
time: 39ms
memory: 9228kb

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: 10
Accepted
time: 36ms
memory: 11388kb

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: 10
Accepted
time: 39ms
memory: 9720kb

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: 10
Accepted
time: 38ms
memory: 9224kb

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: 10
Accepted
time: 36ms
memory: 9316kb

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: 10
Accepted
time: 255ms
memory: 13008kb

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: 10
Accepted
time: 370ms
memory: 14176kb

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: 10
Accepted
time: 487ms
memory: 13528kb

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: 10
Accepted
time: 697ms
memory: 16928kb

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: 10
Accepted
time: 871ms
memory: 16896kb

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: 42ms
memory: 11664kb

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:

0 1

result:

wrong answer 1st numbers differ - expected: '107', found: '0'

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%