QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408398#7648. 网格图最大流计数qwqwfCompile Error//C++145.5kb2024-05-10 09:57:432024-05-10 09:57:45

Judging History

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

  • [2024-05-10 09:57:45]
  • 评测
  • [2024-05-10 09:57:43]
  • 提交

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 s[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>>(s[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(s[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(s[j+1][p]=='1') Add(dp[j+1][p],dp[j][p]);
			if(s[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;
}

詳細信息

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:3:
/usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/queue:63,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:157:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~