QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#231019#7648. 网格图最大流计数Lynkcat10 366ms8604kbC++174.4kb2023-10-28 23:13:192023-10-28 23:13:21

Judging History

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

  • [2023-10-28 23:13:21]
  • 评测
  • 测评结果:10
  • 用时:366ms
  • 内存:8604kb
  • [2023-10-28 23:13:19]
  • 提交

answer

// Lynkcat.
// Problem: P7736 [NOI2021] 路径交点
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P7736
// Memory Limit: 1024 MB
// Time Limit: 1000 ms

#include<bits/stdc++.h>
#define poly vector<int>
#define matrix vector<poly>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 1000000007
#define int ll
using namespace std;
int n,m,K;
int a[405],b[405],usd[405][405];
int f[405][405],pth[405][405];
int quickPower(int x,int y)
{
	int res=1;
	while (y)
	{
		if (y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
matrix mul(matrix &a,matrix &b)
{
	matrix res(a.size(),poly(b[0].size(),0));
	int n=a.size(),m=b[0].size();
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++)
			for (int k=0;k<b.size();k++)
				res[i][j]=(res[i][j]+a[i][k]*b[k][j]%mod)%mod;
	return res;
}
int calc(matrix x)
{
	int n=x.size();
	int l=0;
	int ans=1;
	int fh=1;
	for (int i=0;i<n;i++)
	{
		if (!x[l][i])
		{
			for (int j=l+1;j<n;j++)
				if (x[j][i]) 
				{
					swap(x[l],x[j]);
					fh*=-1;
					break;
				}
		}
		if (!x[l][i]) 
		{
			ans=ans*0;
			continue;
		}
		ans=ans*x[l][i]%mod;
		int inv=quickPower(x[l][i],mod-2)%mod;
		for (int j=i;j<n;j++)
			x[l][j]=x[l][j]*inv%mod;
		for (int j=l+1;j<n;j++)
		{
			int o=x[j][i];
			for (int k=i;k<n;k++)
				x[j][k]=(x[j][k]-x[l][k]*o%mod+mod)%mod;
		}
		l++;
	}
	fh=(mod+fh)%mod;
	return fh*ans%mod;
}

void init()
{
    for (int i=1;i<=n;i++)
    {
        for (int x=1;x<=K;x++)
            for (int y=1;y<=K;y++)
                f[x][y]=0;
        f[1][a[i]]=1;
        for (int x=1;x<=K;x++)
            for (int y=1;y<=K;y++)
            {
                if (usd[x][y]) f[x][y]=(f[x][y]+f[x][y-1]+f[x-1][y])%mod;
            }
        for (int j=1;j<=m;j++) 
        {
            // cout<<i<<" "<<j<<" "<<f[K][b[j]]<<endl;
            pth[i][j]=f[K][b[j]];
        }
    }
}
int gtans()
{
    int tot=0;
    for (int i=1;i<=n;i++)
    {
        if (!usd[1][a[i]]) continue;
        for (int x=1;x<=K;x++)
            for (int y=1;y<=K;y++)
                f[x][y]=0;
        f[1][a[i]]=1;
        for (int x=1;x<=K;x++)
            for (int y=1;y<=K;y++)
            {
                if (usd[x][y]) f[x][y]|=f[x-1][y]|f[x][y-1];
            }
        for (int j=1;j<=m;j++)
            if (f[K][b[j]])
            {
                tot++;
                int x=K,y=b[j];
                while (x!=1||y!=a[i])
                {
                    // assert(usd[x][y]);
                    // cout<<x<<" "<<y<<endl;
                    usd[x][y]=0;
                    if (f[x][y-1]) y--;
                    else x--;
                }
                // assert(usd[x][y]);
                usd[x][y]=0;
                break;
            }
    }
    return tot;
}    
void BellaKira()
{
    cin>>n>>m>>K;
    for (int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1);
    for (int i=1;i<=m;i++)
        cin>>b[i];
    sort(b+1,b+m+1);
    for (int i=1;i<=K;i++)
        for (int j=1;j<=K;j++)
        {
            char ch;
            cin>>ch;
            usd[i][j]=ch-'0';
        }
    init();
    int k=4;
    a[1]=gtans();
    a[k]=a[1];
    a[2]=n,a[3]=m;

	matrix nw(n,poly(m,0));
	// for (int i=0;i<a[1];i++)
	// 	nw[i][i]=1;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++) nw[i][j]=pth[i+1][j+1];
    }
	// for (int i=1;i<k;i++)
	// {
	// 	matrix now(a[i],poly(a[i+1],0));
    //     if (i==1)
    //     {
    //         for (int x=0;x<a[i];x++)
    //             for (int y=0;y<a[i+1];y++) now[x][y]=1;
    //     } else
    //     if (i==3)
    //     {
    //         for (int x=0;x<a[i];x++)
    //             for (int y=0;y<a[i+1];y++) now[x][y]=1;
    //     } else
    //     {
    //         for (int x=0;x<a[i];x++)
    //             for (int y=0;y<a[i+1];y++) now[x][y]=pth[x+1][y+1];
    //     }
	// 	nw=mul(nw,now);
    //     {
    //         for (int i=0;i<nw.size();i++)
    //         {
    //             for (int j=0;j<nw[i].size();j++) cout<<nw[i][j]<<" ";
    //             cout<<'\n';
    //         }
    //     }
    //     cout<<'\n';
	// }
	cout<<a[1]<<" "<<calc(nw)<<'\n';
		
}
signed main()
{
	IOS;
	int T=1;
	while (T--)
	{
		BellaKira();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 1ms
memory: 5632kb

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: 1ms
memory: 5652kb

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: 3696kb

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: -5
Wrong Answer
time: 1ms
memory: 5688kb

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 0

result:

wrong answer 2nd numbers differ - expected: '52', found: '0'

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: 10
Accepted

Test #31:

score: 10
Accepted
time: 87ms
memory: 7428kb

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: 81ms
memory: 7496kb

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: 82ms
memory: 7504kb

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: 84ms
memory: 7696kb

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: 81ms
memory: 7464kb

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: 230ms
memory: 7152kb

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: 266ms
memory: 7256kb

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: 297ms
memory: 8052kb

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: 325ms
memory: 8396kb

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: 366ms
memory: 8604kb

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: 126ms
memory: 7628kb

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 818209365

result:

wrong answer 2nd numbers differ - expected: '3979643', found: '818209365'

Subtask #7:

score: 0
Skipped

Dependency #1:

0%