QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140119#5411. 杏仁Lynkcat#10 154ms53888kbC++172.4kb2023-08-15 09:24:062024-07-04 01:42:55

Judging History

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

  • [2024-07-04 01:42:55]
  • 评测
  • 测评结果:10
  • 用时:154ms
  • 内存:53888kb
  • [2023-08-15 09:24:06]
  • 提交

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[1<<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<=100000;i++) pw[i]=1ll*pw[i-1]*2%mod;
	cin>>n>>m;
	cin>>s>>t;
	s--,t--;
	// for (int i=0;i<n;i++)
		// for (int j=i+1;j<n;j++)
			// f[i][j]=1,f[j][i]=1;
	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)]=f[i][t];
	for (int i=0;i<(1<<n);i++)
		for (int x=0;x<n;x++)
			if ((i>>x)&1)
				if (dp[x][i])
				{
					for (int y=0;y<n;y++)
						if (y!=s&&y!=t&&!((i>>y)&1))
						{
							int v=1ll*dp[x][i]*f[y][x]%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=1ll*dp[x][i]*f[s][x]%mod;
			dp[x][i]=coef;
			sm[i]=(sm[i]+coef>=mod?sm[i]+coef-mod:sm[i]+coef);
		}
	F[0]=1;
	for (int i=1;i<(1<<n);i++)
		if (!((i>>s)&1)&&!((i>>t)&1))
		{
			int t=__lg(i);
			int nw=0;
			for (int j=i;j;j=(j-1)&i)
			{
				if (((j>>t)&1))
				{
					nw=(nw+1ll*F[i^j]*sm[j]%mod);
				} else break;
			}
			nw%=mod;
			F[i]=nw;
		}
	// return;
	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<<1ll*F[(1<<n)-1-(1<<s)-(1<<t)]
			*(pw[f[s][t]]-1)%mod<<'\n';
			continue;
		}
		int ans=0;
		for (int i=0;i<(1<<n);i++)
			if ((i>>x)&1)
				if (dp[x][i])
					ans=(ans+1ll*F[ful^i]*dp[x][i]%mod)%mod;
		cout<<1ll*ans*(pw[f[s][t]])%mod<<'\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: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 13872kb

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: 2ms
memory: 7744kb

input:

2 0
1 2
0

output:


result:

ok 0 lines

Test #3:

score: 0
Accepted
time: 2ms
memory: 11860kb

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
225
224
0

result:

ok 4 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 15880kb

input:

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

output:

24
12
18
22
22

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 3ms
memory: 13964kb

input:

6 20
4 5
4 5
4 1
5 3
2 6
3 5
3 5
5 3
1 4
2 5
4 5
3 5
1 3
3 5
4 2
4 4
3 5
6 5
1 6
5 6
4 4
6
2
3
5
6
1
3

output:

52
0
60
0
68
0

result:

ok 6 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 26132kb

input:

11 20
3 1
3 1
3 7
9 1
4 9
7 4
9 11
6 11
9 5
3 5
3 7
8 9
1 7
10 1
6 11
11 5
3 7
8 10
7 1
9 7
11 8
10
2
10
7
8
11
1
6
9
5
1

output:

0
0
18
0
0
10
0
0
0
10

result:

ok 10 lines

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #7:

score: 0
Wrong Answer
time: 0ms
memory: 24156kb

input:

11 9728
6 10
6 10
9 10
5 10
6 4
4 10
1 6
8 10
3 8
1 10
9 7
5 3
6 4
6 5
11 6
9 6
6 6
3 10
2 4
2 11
6 10
6 2
6 5
10 6
2 10
11 2
9 10
1 10
9 10
7 8
3 1
8 3
3 7
9 11
2 9
6 4
10 11
8 4
2 10
11 10
6 3
6 10
6 11
1 11
6 9
7 11
8 3
9 7
2 1
11 2
6 2
4 1
3 10
6 6
6 11
3 2
10 10
7 10
7 10
6 6
6 8
4 3
4 10
4 2
1...

output:

96270446
231783986
852371251
825992635
617956835
904666058
396119107
772382381
955768651
925763064
852371251

result:

wrong answer 1st lines differ - expected: '18074853', found: '96270446'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 154ms
memory: 53888kb

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:

432858182
432858182
961321969
432858182
432858182
432858182
432858182
432858182
432858182
432858182
432858182
432858182
432858182
432858182
432858182
432858182
432858182
432858182

result:

wrong answer 1st lines differ - expected: '256104819', found: '432858182'

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:

100%
Accepted

Dependency #2:

0%