QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#344288 | #7648. 网格图最大流计数 | Crysfly | 0 | 77ms | 28936kb | C++17 | 6.2kb | 2024-03-03 22:41:34 | 2024-03-03 22:41:35 |
Judging History
answer
// what is matter? never mind.
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000007
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 1005
#define inf 0x3f3f3f3f
#define poly vector<modint>
template<class T>
poly Char(int n,T a){
static modint f[1005][1005];
For(i,1,n-1){
int p=-1;
For(j,i+1,n)
if(a[j][i].x){p=j;break;}
if(p==-1)continue;
else if(p!=i+1){
For(j,1,n)swap(a[p][j],a[i+1][j]);
For(j,1,n)swap(a[j][p],a[j][i+1]);
}
For(j,i+2,n){
modint tmp=a[j][i]/a[i+1][i];
For(k,1,n)a[j][k]-=tmp*a[i+1][k];
For(k,1,n)a[k][i+1]+=tmp*a[k][j];
}
}
f[0][0]=1;
For(i,1,n){
For(j,0,n)f[i][j]=0;
For(j,1,i-1){
modint tmp=a[j][i];
For(k,j,i-1)tmp*=a[k+1][k];
For(k,0,i)f[i][k]-=tmp*f[j-1][k];
}
For(j,1,n)f[i][j]+=f[i-1][j-1];
For(j,0,n)f[i][j]-=a[i][i]*f[i-1][j];
}
return poly(f[n],f[n]+n+1);
}
template<class T>
modint det(int n,T a){
modint res=1;
For(j,1,n){
For(i,j,n)
if(a[i][j].x){
if(i!=j){
res=-res;
For(k,i,n)swap(a[i][k],a[j][k]);
}
break;
}
if(!a[j][j].x)return 0;
res*=a[j][j];
modint iv=1/a[j][j];
For(i,j+1,n){
modint tmp=a[i][j]*iv;
For(k,j,n)a[i][k]-=a[j][k]*tmp;
}
}
return res;
}
template<class T>
modint pf(int n,T a){
modint res=1;
for(int i=1;i<=n;i+=2){
if(!a[i][i+1].x){
int k=i+1;
while(k<=n && !a[i][k].x)++k;
if(k>n)return 0;
swap(a[i][i+1],a[i][k]);
For(j,k+1,n)swap(a[i+1][j],a[k][j]);
For(j,i+2,k-1)swap(a[i+1][j],a[j][k]),a[j][k]=-a[j][k],a[i+1][j]=-a[i+1][j];
a[i+1][k]=-a[i+1][k];
res=-res;
}
res*=a[i][i+1];
modint I=1/a[i][i+1];
For(j,i+2,n){
modint r=a[i][j]*I;
For(k,j+1,n)a[j][k]-=r*a[i+1][k];
For(k,i+2,j-1)a[k][j]+=r*a[i+1][k];
}
}
return res;
}
template<class T>
poly detpoly(int n,int d,T a){
static modint b[1005][1005];
int out=0;
modint coe=1;
For(i,1,n){
int p=n+1;
For(re,0,d){
For(j,1,i-1)if(a[d][j][i].x){
modint t=-a[d][j][i];
For(e,0,d) For(k,1,n) a[e][k][i]+=a[e][k][j]*t;
}
p=i;
while(p<=n && !a[d][p][i])++p;
if(p<=n || re==d)break;
++out;
Rep(e,d,1) For(j,1,n) a[e][j][i]=a[e-1][j][i];
For(j,1,n) a[0][j][i]=0;
}
if(p>n)return poly(n*d+1,0);
if(p>i){
coe=-coe;
For(e,0,d)For(j,1,n)swap(a[e][i][j],a[e][p][j]);
}
coe*=a[d][i][i];
modint I=a[d][i][i];
For(j,i+1,n){
modint t=-a[d][j][i];
if(t.x){ For(e,0,d) For(k,1,n) a[e][j][k]+=t*a[e][i][k]; }
}
}
For(i,1,n*(d-1))b[i][n+i]=1;
For(e,0,d-1)For(i,1,n)For(j,1,n)
b[n*(d-1)+i][n*e+j]=-a[e][i][j];
poly fs=Char(n*d,b);
poly f(n*d+1,0);
For(i,0,n*d-out)f[i]=coe*fs[i+out];
return f;
}
int n,m,k,a[maxn],b[maxn];
char s[405][405];
modint f[405][405],go[405][405],sum[405][405];
modint mat[3][405][405],g[405][405];
modint res[405];
signed main()
{
n=read(),m=read(),k=read();
For(i,1,n)a[i]=read();
For(i,1,m)b[i]=read();
For(i,1,k)scanf("%s",s[i]+1);
For(i,1,n){
memset(f,0,sizeof f);
f[1][a[i]]=1;
For(x,1,k)For(y,1,k)
if(s[x][y]=='1')f[x+1][y]+=f[x][y],f[x][y+1]+=f[x][y];
else f[x][y]=0;
For(j,1,m) go[i][j]=f[k][b[j]];
}
// if(n%2) ++n,++m,go[n][m]=1;
For(i,1,n)For(j,1,m)sum[i][j]=sum[i][j-1]+go[i][j];
For(i,1,n)For(j,i+1,n){
For(k,1,m){
modint t=sum[i][k]*go[j][k]-sum[j][k]*go[i][k];
g[i][j]+=t;
g[j][i]-=t;
}
}
//For(i,1,n)For(j,1,n)cout<<mat[i][j].x<<" \n"[j==n];
int len=(n%2==0?n+2:n+1);
For(i,1,len) For(j,i+1,len) {
mat[0][i][j]+=sign(j-i-1);
if(i<=n && j<=n) mat[2][i][j]=g[i][j];
}
For(i,1,n) mat[1][i][len]=sum[i][n];
For(d,0,2) For(i,1,len) For(j,i+1,len) mat[d][j][i]=-mat[d][i][j];
// For(d,0,2){
// For(i,1,len)For(j,1,len)cout<<mat[d][i][j].x<<" \n"[j==len];
// puts("-----------");
// }
poly ans=detpoly(len,3,mat);
res[0]=1;
For(i,1,n){
res[i]=ans[i];
For(j,1,i-1)res[i]-=ans[j]*ans[i-j];
res[i]*=((mod+1)/2);
}
Rep(i,n,0)
if(res[i].x){
cout<<i<<" "<<res[i].x<<"\n";
exit(0);
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 28936kb
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 505408902
result:
wrong answer 2nd numbers differ - expected: '1', found: '505408902'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 77ms
memory: 28712kb
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 520260194
result:
wrong answer 2nd numbers differ - expected: '849796347', found: '520260194'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%