QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#362261 | #7648. 网格图最大流计数 | -Ofast# | 20 | 899ms | 222240kb | C++14 | 2.4kb | 2024-03-23 14:47:07 | 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;
signed dp[N][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: 9732kb
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: 9956kb
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: 2ms
memory: 12000kb
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: 0ms
memory: 9788kb
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: 1ms
memory: 7824kb
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: 899ms
memory: 145752kb
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: 30ms
memory: 22476kb
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: 220ms
memory: 51056kb
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: 34ms
memory: 24292kb
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: 176ms
memory: 53716kb
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: 10
Accepted
Test #31:
score: 10
Accepted
time: 68ms
memory: 54236kb
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: 59ms
memory: 51644kb
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: 63ms
memory: 53876kb
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: 61ms
memory: 53016kb
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: 63ms
memory: 52628kb
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: 178ms
memory: 139552kb
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: 226ms
memory: 158332kb
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: 251ms
memory: 181704kb
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: 289ms
memory: 201740kb
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: 331ms
memory: 222240kb
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
Time Limit Exceeded
Dependency #5:
100%
Accepted
Test #41:
score: 0
Time Limit Exceeded
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:
result:
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%