QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#344294 | #7648. 网格图最大流计数 | Crysfly | 15 | 1140ms | 16484kb | C++17 | 6.3kb | 2024-03-03 23:20:06 | 2024-03-03 23:20:07 |
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].x)++p;
if(p<=n || re==d)break;
++out;
Rep(e,d,re) 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=1/a[d][i][i];
For(e,0,d)For(j,1,n)a[e][i][j]*=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,2,mat);
// for(auto x:ans)cout<<x.x<<" "; cout<<"\n";
res[0]=1;
For(i,1,n){
res[i]=ans[i];
For(j,1,i-1)res[i]-=res[j]*res[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: 5
Accepted
Test #1:
score: 5
Accepted
time: 4ms
memory: 16252kb
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: 16252kb
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: 16244kb
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: 4ms
memory: 16224kb
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: 0ms
memory: 16208kb
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: 5
Accepted
time: 4ms
memory: 16484kb
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: -5
Wrong Answer
time: 2ms
memory: 16476kb
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:
14 673258500
result:
wrong answer 1st numbers differ - expected: '15', found: '14'
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: 43ms
memory: 16324kb
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: 39ms
memory: 16240kb
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: 51ms
memory: 16320kb
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: 44ms
memory: 16248kb
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: 38ms
memory: 16268kb
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: 342ms
memory: 16276kb
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: 497ms
memory: 16296kb
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: 677ms
memory: 16244kb
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: 879ms
memory: 16292kb
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: 1140ms
memory: 16324kb
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: 93ms
memory: 16316kb
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 350064262
result:
wrong answer 2nd numbers differ - expected: '3979643', found: '350064262'
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%