QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#480483#7412. Counting Cactusstrlen_s_WA 0ms3880kbC++142.7kb2024-07-16 16:03:442024-07-16 16:03:44

Judging History

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

  • [2024-07-16 16:03:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3880kb
  • [2024-07-16 16:03:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=15,M=(1<<13)+5,mod=998244353,inv2=499122177;
int a[N];
int n,m,ans;
int g[M];
int col[N],b[N];
int pt[M];
int A[N][N];
int ksm(int a,int b){
  int res=1;
  while(b){
    if(b&1)res=1ll*res*a%mod;
    a=1ll*a*a%mod,b>>=1;
  }
  return res;
}
int det(int cnt){
  int res=1;
  for(int i=1;i<=cnt;i++){
    int p=i;
    if(!A[p][i]){
      p=0;
      for(int j=i+1;j<=cnt;j++){
        if(A[j][i]){p=j;break;}
      }
      if(p==0)return 0;
      res=mod-res;
      for(int j=i;j<=cnt;j++)swap(A[p][j],A[i][j]);
    }
    res=1ll*res*A[i][i]%mod;
    int inv=ksm(A[i][i],mod-2);
    for(int j=1;j<=cnt;j++){
      if(j==i)continue;
      int xs=1ll*A[j][i]*inv%mod;
      for(int k=i;k<=cnt;k++)
        A[j][k]=(A[j][k]+mod-1ll*A[i][k]*xs%mod)%mod;
    }
  }
  return res;
}
void work(int cnt){
  int res=1;
  for(int i=1;i<=cnt;i++)res=1ll*res*g[col[i]]%mod;
  if(!res)return;
  for(int i=1;i<cnt;i++){
    int sd=0;
    for(int j=1;j<=n;j++)if(col[i]>>(j-1)&1)sd+=pt[b[j]^(b[j]&col[i])];
    A[i][i]=sd;
    for(int j=i+1;j<cnt;j++){
      sd=0;
      for(int k=1;k<=n;k++)if(col[i]>>(k-1)&1)sd+=pt[(b[k]^(b[k]&col[i]))&col[j]];
      A[i][j]=A[j][i]=(mod-sd)%mod;
    }
  }
  ans=(ans+1ll*res*det(cnt-1));
}
void dfs(int x,int cl,int st,int cnt){
  if(x>n){
    if(cnt==2)return;
    work(cl);
    return;
  }
  if(st>n){
    if(cnt!=2&&g[col[cl]])dfs(x,cl+1,1,0);
    return;
  }
  if(!cnt){
    for(;a[st];st++);
    a[st]=cl;col[cl]|=(1<<st-1);
    dfs(x+1,cl,st+1,1);
    a[st]=0;col[cl]^=(1<<st-1);
    return;
  }
  if(a[st]){
    dfs(x,cl,st+1,cnt);
    return;
  }
  dfs(x,cl,st+1,cnt);
  a[st]=cl;col[cl]|=(1<<st-1);
  dfs(x+1,cl,st+1,cnt+1);
  a[st]=0;col[cl]^=(1<<st-1);
}
int dp[M][N];
int rec[N],tot;
int calc(int s){
  int res=0;tot=0;
  for(int i=1;i<=n;i++)if(s>>(i-1)&1)rec[++tot]=i;
  if(tot==1)return 1;
  if(tot==2)return 0;
  for(int i=0;i<(1<<tot);i++)
    for(int j=1;j<=tot;j++)
      dp[i][j]=0;
  dp[1][1]=1;
  for(int i=1;i<(1<<tot);i++){
    for(int j=1;j<=tot;j++){
      if((!(i>>(j-1)&1))||(!dp[i][j]))continue;
      for(int k=1;k<=tot;k++){
        if((i>>(k-1)&1)||(!(b[rec[j]]&(1<<rec[k]-1))))continue;
        if((i|(1<<k-1))==(1<<tot)-1){
          if(b[rec[1]]&(1<<rec[k]-1))res=(res+dp[i][j])%mod;
          continue;
        }
        dp[i|(1<<k-1)][k]=(dp[i|(1<<k-1)][k]+dp[i][j])%mod;
      }
    }
  }
  return 1ll*res*inv2%mod;
}
signed main(){
  cin>>n>>m;
  for(int i=1,x,y;i<=m;i++){
    cin>>x>>y;
    b[x]|=(1<<y-1);
    b[y]|=(1<<x-1);
  }
  for(int i=1;i<(1<<n);i++)g[i]=calc(i),pt[i]=__builtin_popcount(i);
  dfs(1,1,1,0);
  cout<<ans<<'\n';
  return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3520kb

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

input:

5 0

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

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: 0ms
memory: 3868kb

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

input:

1 0

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

2 0

output:

0

result:

ok 1 number(s): "0"

Test #7:

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

input:

2 1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #8:

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

input:

3 0

output:

0

result:

ok 1 number(s): "0"

Test #9:

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

input:

3 1
2 3

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

input:

3 2
1 2
2 3

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

3 3
1 2
1 3
2 3

output:

4

result:

ok 1 number(s): "4"

Test #12:

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

input:

4 0

output:

0

result:

ok 1 number(s): "0"

Test #13:

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

input:

4 1
1 4

output:

0

result:

ok 1 number(s): "0"

Test #14:

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

input:

4 2
1 4
1 2

output:

0

result:

ok 1 number(s): "0"

Test #15:

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

input:

4 3
1 3
2 3
2 4

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

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

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

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: 0ms
memory: 3796kb

input:

5 1
2 3

output:

0

result:

ok 1 number(s): "0"

Test #20:

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

input:

5 2
1 3
1 2

output:

0

result:

ok 1 number(s): "0"

Test #21:

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

input:

5 3
2 4
3 4
1 5

output:

0

result:

ok 1 number(s): "0"

Test #22:

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

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: 0ms
memory: 3640kb

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: 0ms
memory: 3636kb

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: -100
Wrong Answer
time: 0ms
memory: 3628kb

input:

5 7
4 5
2 4
2 3
1 5
1 3
1 2
2 5

output:

40

result:

wrong answer 1st numbers differ - expected: '41', found: '40'