QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#422318 | #7412. Counting Cactus | Harry27182 | WA | 1ms | 7956kb | C++14 | 1.6kb | 2024-05-27 11:38:26 | 2024-05-27 11:38:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,e[15][15],f[15][10005][15],dp[10005],val[10005],tmp[10005];
const int mod=998244353;
void Add(int &x,int y){x=(x+y>=mod?x+y-mod:x+y);}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m;
for(int i=1;i<=m;i++)cin>>x>>y,x--,y--,e[x][y]=e[y][x]=1;
for(int i=0;i<n;i++)f[i][1<<i][i]=1;
for(int i=0;i<n;i++)
{
for(int s=0;s<(1<<n);s++)
{
for(int j=0;j<n;j++)
{
if(!f[i][s][j])continue;
for(int k=0;k<n;k++)
{
if((s>>k)&1)continue;
if(e[j][k])Add(f[i][s|(1<<k)][k],f[i][s][j]);
}
}
}
}
for(int i=0;i<n;i++)
{
for(int s=0;s<(1<<n);s++)
{
if(__builtin_popcount(s)<=2)continue;
for(int j=0;j<n;j++)
{
if(!f[i][s][j])continue;
if(e[j][i]&&__builtin_ctz(s)==i)Add(val[s],f[i][s][j]);
}
}
}
for(int i=0;i<n;i++)val[1<<i]=2;
for(int s=0;s<(1<<n);s++)val[s]=1ll*val[s]*((mod+1)>>1)%mod;
for(int s=1;s<(1<<n);s++)dp[s]=val[s];
for(int i=0;i<n;i++)
{
for(int s=0;s<(1<<n);s++)
{
if(!((s>>i)&1))continue;
int S=s^(1<<i),mn=__builtin_ctz(S);
for(int t=S&(S-1);t;t=S&(t-1))
{
if((t>>mn)&1)
{
if(__builtin_popcount(S^t)<2||__builtin_popcount(t)<2)continue;
Add(dp[s],1ll*dp[(S^t)|(1<<i)]*dp[t|(1<<i)]%mod);
}
}
}
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(!e[i][j])continue;
for(int s=1;s<(1<<n);s++)tmp[s]=dp[s];
for(int s=1;s<(1<<n);s++)
{
for(int t=s&(s-1);t;t=s&(t-1))
{
if((((s^t)>>i)&1)&&((t>>j)&1))Add(dp[s],1ll*tmp[s^t]*tmp[t]%mod);
}
}
}
}
cout<<dp[(1<<n)-1];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5688kb
input:
3 3 1 2 2 3 3 1
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5900kb
input:
5 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 7832kb
input:
8 9 1 5 1 8 2 4 2 8 3 4 3 6 4 7 5 7 6 8
output:
35
result:
ok 1 number(s): "35"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7668kb
input:
6 8 5 6 2 5 3 5 1 5 1 2 3 4 1 6 1 3
output:
38
result:
ok 1 number(s): "38"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
1 0
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 5672kb
input:
2 0
output:
0
result:
ok 1 number(s): "0"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5644kb
input:
2 1 1 2
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5604kb
input:
3 0
output:
0
result:
ok 1 number(s): "0"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
3 1 2 3
output:
0
result:
ok 1 number(s): "0"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
3 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 1ms
memory: 5720kb
input:
3 3 1 2 1 3 2 3
output:
4
result:
ok 1 number(s): "4"
Test #12:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
4 0
output:
0
result:
ok 1 number(s): "0"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
4 1 1 4
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 1ms
memory: 5668kb
input:
4 2 1 4 1 2
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 0ms
memory: 5624kb
input:
4 3 1 3 2 3 2 4
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
4 4 2 3 2 4 3 4 1 3
output:
4
result:
ok 1 number(s): "4"
Test #17:
score: 0
Accepted
time: 0ms
memory: 5628kb
input:
4 5 2 3 2 4 1 3 3 4 1 2
output:
13
result:
ok 1 number(s): "13"
Test #18:
score: 0
Accepted
time: 0ms
memory: 5620kb
input:
4 6 3 4 1 2 1 3 2 3 1 4 2 4
output:
31
result:
ok 1 number(s): "31"
Test #19:
score: 0
Accepted
time: 1ms
memory: 5568kb
input:
5 1 2 3
output:
0
result:
ok 1 number(s): "0"
Test #20:
score: 0
Accepted
time: 1ms
memory: 7908kb
input:
5 2 1 3 1 2
output:
0
result:
ok 1 number(s): "0"
Test #21:
score: 0
Accepted
time: 1ms
memory: 5908kb
input:
5 3 2 4 3 4 1 5
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 1ms
memory: 5556kb
input:
5 4 3 5 4 5 2 3 3 4
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 1ms
memory: 5624kb
input:
5 5 1 5 4 5 3 5 1 3 2 4
output:
4
result:
ok 1 number(s): "4"
Test #24:
score: 0
Accepted
time: 1ms
memory: 7952kb
input:
5 6 1 5 4 5 1 4 2 3 1 3 3 5
output:
13
result:
ok 1 number(s): "13"
Test #25:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
5 7 4 5 2 4 2 3 1 5 1 3 1 2 2 5
output:
41
result:
ok 1 number(s): "41"
Test #26:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
5 8 4 5 2 3 3 5 1 2 2 4 2 5 1 4 1 5
output:
90
result:
ok 1 number(s): "90"
Test #27:
score: 0
Accepted
time: 0ms
memory: 5684kb
input:
5 9 4 5 1 4 1 5 1 2 3 5 2 4 2 5 1 3 3 4
output:
192
result:
ok 1 number(s): "192"
Test #28:
score: 0
Accepted
time: 1ms
memory: 5560kb
input:
5 10 2 4 1 5 2 5 1 4 2 3 3 4 1 2 3 5 4 5 1 3
output:
362
result:
ok 1 number(s): "362"
Test #29:
score: 0
Accepted
time: 0ms
memory: 5656kb
input:
6 1 1 5
output:
0
result:
ok 1 number(s): "0"
Test #30:
score: 0
Accepted
time: 1ms
memory: 7956kb
input:
6 3 3 4 3 5 2 6
output:
0
result:
ok 1 number(s): "0"
Test #31:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
6 4 4 5 4 6 5 6 1 3
output:
0
result:
ok 1 number(s): "0"
Test #32:
score: 0
Accepted
time: 1ms
memory: 5728kb
input:
6 6 4 5 2 6 2 5 5 6 1 6 2 3
output:
4
result:
ok 1 number(s): "4"
Test #33:
score: 0
Accepted
time: 0ms
memory: 7664kb
input:
6 7 5 6 4 5 3 6 1 6 2 6 1 2 3 4
output:
20
result:
ok 1 number(s): "20"
Test #34:
score: 0
Accepted
time: 1ms
memory: 7788kb
input:
6 9 2 3 5 6 4 5 1 6 1 5 4 6 1 4 3 4 2 4
output:
124
result:
ok 1 number(s): "124"
Test #35:
score: 0
Accepted
time: 1ms
memory: 7584kb
input:
6 10 2 6 2 3 3 5 1 6 2 4 1 4 1 5 3 6 5 6 4 6
output:
311
result:
ok 1 number(s): "311"
Test #36:
score: 0
Accepted
time: 1ms
memory: 5732kb
input:
6 12 1 4 2 3 4 6 1 3 2 4 3 5 1 5 1 6 3 6 5 6 3 4 2 5
output:
1150
result:
ok 1 number(s): "1150"
Test #37:
score: 0
Accepted
time: 1ms
memory: 7668kb
input:
6 13 3 6 3 5 1 6 1 4 1 3 3 4 4 6 2 5 1 2 4 5 2 3 2 6 2 4
output:
1956
result:
ok 1 number(s): "1956"
Test #38:
score: 0
Accepted
time: 1ms
memory: 7728kb
input:
6 15 5 6 3 6 2 5 1 5 3 4 2 3 3 5 1 4 2 4 1 2 4 5 1 3 2 6 4 6 1 6
output:
5676
result:
ok 1 number(s): "5676"
Test #39:
score: 0
Accepted
time: 1ms
memory: 7772kb
input:
7 2 1 5 1 4
output:
0
result:
ok 1 number(s): "0"
Test #40:
score: 0
Accepted
time: 1ms
memory: 7680kb
input:
7 4 1 2 3 4 2 4 2 7
output:
0
result:
ok 1 number(s): "0"
Test #41:
score: 0
Accepted
time: 1ms
memory: 5676kb
input:
7 6 1 7 2 3 6 7 1 4 4 6 3 6
output:
0
result:
ok 1 number(s): "0"
Test #42:
score: 0
Accepted
time: 0ms
memory: 7732kb
input:
7 8 4 6 6 7 3 4 5 7 1 7 1 5 1 4 1 3
output:
0
result:
ok 1 number(s): "0"
Test #43:
score: 0
Accepted
time: 1ms
memory: 5704kb
input:
7 10 1 5 1 6 2 7 5 6 4 7 3 5 2 3 4 6 1 3 4 5
output:
181
result:
ok 1 number(s): "181"
Test #44:
score: 0
Accepted
time: 1ms
memory: 7720kb
input:
7 12 1 2 1 3 5 7 4 6 3 7 2 3 2 6 4 7 3 5 1 6 2 5 4 5
output:
1039
result:
ok 1 number(s): "1039"
Test #45:
score: -100
Wrong Answer
time: 0ms
memory: 7680kb
input:
7 14 1 6 2 7 1 5 1 2 2 6 3 7 3 6 1 3 1 4 3 5 1 7 6 7 4 5 2 4
output:
3610
result:
wrong answer 1st numbers differ - expected: '3604', found: '3610'