QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#362251 | #7648. 网格图最大流计数 | -Ofast# | 10 | 855ms | 155880kb | C++14 | 2.4kb | 2024-03-23 14:46:06 | 2024-07-04 03:30:36 |
Judging History
answer
#include <bits/stdc++.h>
#define mp make_pair
#define fir first
#define sec second
#define mt make_tuple
#define int long long
#define fin(File) freopen(File".in","r",stdin)
#define fout(File) freopen(File".out","w",stdout)
using namespace std;
const int N=410;
const int mod=1e9+7;
int n,m,k,a[N],b[N];
char s[N][N];
int qpow(int a,int b){
a%=mod;int res=1;
while(b){
if(b&1)res=(res*a)%mod;
a=(a*a)%mod;b>>=1;
}return res;
}
int mat[N][N];
int Gauss(int n){
int det=1;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
while(mat[i][i]){
int tmp=mat[j][i]/mat[i][i];
for(int k=i;k<=n;k++)
mat[j][k]-=mat[i][k]*tmp%mod,mat[j][k]=(mat[j][k]+mod)%mod;
for(int k=i;k<=n;k++)
swap(mat[i][k],mat[j][k]);
det*=-1;
}
for(int k=i;k<=n;k++)
swap(mat[i][k],mat[j][k]);
det*=-1;
}
}det=(det+mod)%mod;
for(int i=1;i<=n;i++)
det*=mat[i][i],det=det%mod;
return det;
}
int flg=0,ans=0;
int dp[55][N][N];
map <pair<pair<int,int>,pair<vector<int>,vector<int>>>,int> vis;
void dfs(int x,int y,vector <int> A,vector <int> B,int p){
if(vis.count(mp(mp(x,y),mp(A,B))))return;
vis[mp(mp(x,y),mp(A,B))]=1;
if(p==A.size()){
//cout<<"st: "<<endl;
//for(auto it:A)cout<<it<<" ";
//cout<<endl;
//for(auto it:B)cout<<it<<" ";
//cout<<endl;
for(int i=1;i<=p;i++){
for(int j=1;j<=p;j++){
mat[i][j]=dp[A[i-1]][k][b[B[j-1]]];
}
}
int now=Gauss(p);
//cout<<now<<endl;
if(now)flg=1;
ans+=now;ans%=mod;
}
if(x>n||y>m)return;
if(min(n-x+1,m-y+1)+A.size()<p)return;
dfs(x,y+1,A,B,p);
if(a[x]<=b[y]){
dfs(x+1,y,A,B,p);
A.push_back(x);
B.push_back(y);
dfs(x+1,y+1,A,B,p);
}
}
void solve(int p){
flg=0;ans=0;vis.clear();
dfs(1,1,vector<int>(),vector<int>(),p);
if(flg){
cout<<p<<" "<<ans<<"\n";
exit(0);
}
}
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<=m;i++)cin>>b[i];
sort(a+1,a+1+n);sort(b+1,b+1+m);
for(int i=1;i<=k;i++)cin>>(s[i]+1);
for(int p=1;p<=n;p++){
dp[p][1][a[p]]=1;
for(int i=1;i<=k;i++){
for(int j=1;j<=k;j++){
if(s[i][j]=='0')dp[p][i][j]=0;
dp[p][i+1][j]+=dp[p][i][j];
dp[p][i][j+1]+=dp[p][i][j];
dp[p][i+1][j]%=mod;
dp[p][i][j+1]%=mod;
}
}
}
for(int i=min(n,m);i>=1;i--)
solve(i);
cout<<0<<" "<<1<<"\n";
return 0;
}
詳細信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 13796kb
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: 2ms
memory: 15916kb
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: 15924kb
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: 2ms
memory: 15892kb
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: 14136kb
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: 855ms
memory: 155880kb
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: 41ms
memory: 34952kb
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: 306ms
memory: 65580kb
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: 31ms
memory: 32556kb
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: 196ms
memory: 64308kb
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: 0
Time Limit Exceeded
Dependency #2:
100%
Accepted
Test #11:
score: 0
Time Limit Exceeded
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:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Runtime Error
Test #31:
score: 0
Runtime Error
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:
result:
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%