QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140107#5411. 杏仁Lynkcat#0 1ms11772kbC++172.3kb2023-08-15 08:50:442024-07-04 02:37:26

Judging History

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

  • [2024-07-04 02:37:26]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:11772kb
  • [2023-08-15 08:50:44]
  • 提交

answer

#include<bits/stdc++.h>
#define poly vector<int>
#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 998244353
#define sz(x) (int)((x).size())
#define int ll
#define N 22
using namespace std;
int dp[N][1<<N];
int pw[100005];
int f[N][N];
int F[1<<N];
int n,m,s,t;
int sm[N];
int q;
inline ll quickPower(ll x,ll y)
{
	ll res=1;
	while (y)
	{
		if (y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
void BellaKira()
{
	pw[0]=1;
	for (int i=1;i<=10000;i++) pw[i]=pw[i-1]*2%mod;
	cin>>n>>m;
	cin>>s>>t;
	s--,t--;
	for (int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--,y--;
		f[x][y]++;
	}
	for (int i=0;i<n;i++)
		if (i!=s&&i!=t)
			dp[i][(1<<i)]=1;
	for (int i=0;i<(1<<n);i++)
		for (int x=0;x<n;x++)
			if ((i>>x)&1)
				if (dp[x][i])
				{
					// cout<<x<<" "<<bitset<5>(i)<<" "<<dp[x][i]<<endl;
					for (int y=0;y<n;y++)
						if (y!=s&&y!=t&&!((i>>y)&1))
						{
							int v=dp[x][i]*(pw[f[y][x]]-1+mod)%mod;
							dp[y][i|(1<<y)]=(dp[y][i|(1<<y)]+v
							>=mod?dp[y][i|(1<<y)]+v-mod:dp[y][i|(1<<y)]+v);
						}
				}
	for (int i=0;i<(1<<n);i++)
		for (int x=0;x<n;x++)
		{
			int coef=dp[x][i]*(pw[f[s][x]]-1+mod)%mod;
			dp[x][i]=coef;
			sm[i]=(sm[i]+coef>=mod?sm[i]+coef-mod:sm[i]+coef);
		}
	F[0]=(pw[f[s][t]]+mod)%mod;
	for (int i=1;i<(1<<n);i++)
		if (!((i>>s)&1)&&!((i>>t)&1))
		{
			int t=__lg(i);
			for (int j=i;j;j=(j-1)&i)
			{
				if (!((j>>t)&1)) break;
				F[i]=(F[i]+F[i^j]*sm[j]%mod)%mod;
			}
		}
	for (int j=0;j<n;j++)
		for (int i=0;i<(1<<n);i++)
			if ((i>>j)&1)
				F[i]=(F[i]+F[i-(1<<j)])%mod;
	cin>>q;
	int ful=(1<<n)-1-(1<<s)-(1<<t);
	// cout<<F[ful]<<endl;
	while (q--)
	{
		int x;
		cin>>x;
		x--;
		// cout<<"??"<<x<<endl;
		if (x==s)
		{
			cout<<0<<'\n';
			continue;
		}
		if (x==t)
		{
			cout<<F[(1<<n)-1-(1<<s)-(1<<t)]*quickPower(pw[f[s][t]],mod-2)%mod
			*(pw[f[s][t]]-1+mod)%mod<<'\n';
			continue;
		}
		int ans=0;
		for (int i=0;i<(1<<n);i++)
			if ((i>>x)&1)
				if (dp[x][i])
					ans=(ans+F[ful^i]*dp[x][i]%mod)%mod;
		cout<<ans<<'\n';
	}
}
signed main()
{
	IOS;
	cin.tie(0);
	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: 10
Accepted
time: 0ms
memory: 11772kb

input:

5 10
1 5
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
4
2
3
4
5

output:

20
14
10
15

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5604kb

input:

2 0
1 2
0

output:


result:

ok 0 lines

Test #3:

score: -10
Wrong Answer
time: 1ms
memory: 9728kb

input:

4 20
1 4
1 4
2 4
1 4
2 4
1 1
3 4
3 1
2 4
1 3
1 3
3 2
2 3
4 1
3 1
2 3
1 4
3 2
4 4
3 1
1 4
4
2
4
3
2

output:

0
195
192
0

result:

wrong answer 2nd lines differ - expected: '225', found: '195'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Runtime Error

Test #15:

score: 0
Runtime Error

input:

18 324
9 8
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 18
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
3 15
3 16
3 17
3 18
4 1
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
4 11
...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Time Limit Exceeded

Test #23:

score: 0
Time Limit Exceeded

input:

22 9384
9 19
9 19
3 18
9 17
9 19
15 19
14 17
9 18
9 14
9 18
9 19
16 19
3 10
9 2
2 1
21 10
1 19
4 3
19 3
9 16
18 21
9 22
9 8
13 8
2 7
4 16
9 12
15 12
3 19
19 10
16 10
14 19
19 16
14 19
1 4
11 5
5 13
3 19
9 6
17 22
4 18
1 13
2 18
19 16
18 17
12 22
21 3
5 11
18 7
14 19
8 19
9 20
16 19
22 19
18 12
9 19
...

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #1:

0%