QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#886344#7. 主旋律gyydp123_LIM100 ✓205ms5504kbC++203.9kb2025-02-06 22:26:532025-02-06 22:26:55

Judging History

This is the latest submission verdict.

  • [2025-02-06 22:26:55]
  • Judged
  • Verdict: 100
  • Time: 205ms
  • Memory: 5504kb
  • [2025-02-06 22:26:53]
  • Submitted

answer

#include<bits/stdc++.h>
template <const unsigned Md> struct modint {
private:
  template <class T>
  using must_int = std::enable_if_t<std::is_integral<T>::value> *;
  struct Mongomery {
    typedef unsigned int uint;
    typedef unsigned long long ull;
    uint mod, niv, R;
    Mongomery() {}
    constexpr Mongomery(const uint &m) : mod(m), niv(m + 2), R((-(ull)m) % m) {
      for (int i = 0; i < 4; i++)
        niv *= (m * niv + 2);
    }
    uint reduce(ull x) const {
      x = ((x + (ull)((uint)x * niv) * mod) >> 32);
      return (x >= mod) ? x - mod : x;
    }
  };
  typedef unsigned int uint;
  typedef unsigned long long ull;
  const static int mod = Md;
  const static unsigned umod = Md;
  const static constexpr Mongomery mont = Mongomery(Md);

public:
  unsigned val;
  modint() : val(0) {}
  modint(unsigned x) : val(mont.reduce((ull)x * mont.R)) {}
  template <class T, must_int<T> = nullptr>
  modint(T x) : modint((unsigned)(x %= mod, x < 0 ? x + mod : x)) {}
  friend int value(const modint &self) { return mont.reduce(self.val); }
  int value() { return mont.reduce(val); }
  modint operator+() { return *this; }
  modint operator-() { return modint() - *this; }
  modint &operator+=(const modint &rhs) {
    val += rhs.val;
    if (val >= umod)
      val -= umod;
    return *this;
  }
  modint &operator-=(const modint &rhs) {
    val -= rhs.val;
    if (val >= umod)
      val += umod;
    return *this;
  }
  modint &operator*=(const modint &rhs) {
    val = mont.reduce((ull)val * rhs.val);
    return *this;
  }
  friend modint qpow(modint a, ull b) {
    modint s(1);
    while (b) {
      if (b & 1)
        s *= a;
      a *= a;
      b >>= 1;
    }
    return s;
  }
  modint &operator/=(const modint &rhs) { return *this *= qpow(rhs, umod - 2); }
  friend modint operator+(modint lhs, const modint &rhs) { return lhs += rhs; }
  friend modint operator-(modint lhs, const modint &rhs) { return lhs -= rhs; }
  friend modint operator*(modint lhs, const modint &rhs) { return lhs *= rhs; }
  friend modint operator/(modint lhs, const modint &rhs) { return lhs /= rhs; }
  bool operator==(const modint &rhs) const { return val == rhs.val; }
  bool operator!=(const modint &rhs) const { return val != rhs.val; }
  modint &operator++() { return *this += modint(1); }
  modint &operator--() { return *this -= modint(1); }
  modint operator++(int) {
    modint tmp = *this;
    ++(*this);
    return tmp;
  }
  modint operator--(int) {
    modint tmp = *this;
    --(*this);
    return tmp;
  }
};
#define For(i,j,k) for(int i=(j);i<=(k);++i)
#define ForDown(i,j,k) for(int i=(j);i>=(k);--i)
#define Debug(fmt, args...) fprintf(stderr,"(func %s, line #%d): " fmt,__func__,__LINE__,##args),fflush(stderr)
#define debug(fmt, args...) fprintf(stderr,fmt,##args),fflush(stderr)
#define within :
#define LJY main
using namespace std;
typedef long long ll;
const int mod=1e9+7,N=15;
using mint=modint<mod>;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
inline int read(){
  char ch=getchar();int x=0,f=1;
  while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
  while(ch>='0'&&ch<='9')
    x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
  return x*f;
}
int n,m,in[N],out[N],cnt[1<<N],pcnt[1<<N],del[1<<N];
mint pw[N*N],f[1<<N],g[1<<N];
void calc(int T,int S){
  if((T-1)&S) calc((T-1)&S,S);
  del[T]=del[T&(T-1)]+pcnt[in[__lg(T&-T)]&S];
}
signed LJY(){
  n=read();m=read();pw[0]=1;
  For(i,1,m){
    int u=read()-1,v=read()-1;
    in[v]|=(1<<u);out[u]|=(1<<v);pw[i]=pw[i-1]+pw[i-1];
  }For(S,1,(1<<n)-1){
    int bt=__lg(S&-S);pcnt[S]=__builtin_popcount(S);
    cnt[S]=cnt[S&(S-1)]+pcnt[in[bt]&S]+pcnt[out[bt]&S];
  }For(S,1,(1<<n)-1){
    calc(S,S);f[S]=pw[cnt[S]];
    int T=S&(S-1);
    for(int i=(S-1)&S;i;i=(i-1)&T) g[S]-=g[i]*f[S^i];
    for(int i=S;i;i=(i-1)&S) f[S]-=g[i]*pw[cnt[S]-del[i]];
    g[S]+=f[S];
  }printf("%d",value(f[(1<<n)-1]));
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

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

input:

5 15
4 3
4 2
2 5
2 1
1 2
5 1
3 2
4 1
1 4
5 4
3 4
5 3
2 3
1 5
3 1

output:

9390

result:

ok single line: '9390'

Test #2:

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

input:

5 18
4 3
4 2
2 5
2 1
1 2
5 1
3 2
4 1
1 4
5 4
3 4
5 3
2 3
1 5
3 1
1 3
5 2
2 4

output:

100460

result:

ok single line: '100460'

Test #3:

score: 10
Accepted
time: 1ms
memory: 4096kb

input:

8 35
5 1
8 7
7 8
7 6
6 1
2 5
6 5
8 2
7 2
7 5
3 1
6 3
2 3
5 2
8 5
8 3
6 8
2 1
1 6
2 6
7 3
2 4
3 5
3 2
3 7
7 1
8 4
3 4
3 6
6 4
2 7
4 6
6 7
7 4
8 1

output:

299463717

result:

ok single line: '299463717'

Test #4:

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

input:

8 40
5 1
8 7
7 8
7 6
6 1
2 5
6 5
8 2
7 2
7 5
3 1
6 3
2 3
5 2
8 5
8 3
6 8
2 1
1 6
2 6
7 3
2 4
3 5
3 2
3 7
7 1
8 4
3 4
3 6
6 4
2 7
4 6
6 7
7 4
8 1
1 2
4 8
5 8
4 3
5 7

output:

21156439

result:

ok single line: '21156439'

Test #5:

score: 10
Accepted
time: 1ms
memory: 4096kb

input:

8 45
5 1
8 7
7 8
7 6
6 1
2 5
6 5
8 2
7 2
7 5
3 1
6 3
2 3
5 2
8 5
8 3
6 8
2 1
1 6
2 6
7 3
2 4
3 5
3 2
3 7
7 1
8 4
3 4
3 6
6 4
2 7
4 6
6 7
7 4
8 1
1 2
4 8
5 8
4 3
5 7
2 8
1 5
3 8
1 3
4 1

output:

426670664

result:

ok single line: '426670664'

Test #6:

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

input:

10 65
5 10
1 8
7 8
6 2
5 7
9 2
4 7
3 7
1 6
3 10
7 9
8 4
7 1
5 2
1 7
4 2
8 3
8 1
3 9
8 2
2 10
4 3
9 10
5 3
3 8
3 4
6 10
4 8
4 5
5 8
9 5
9 6
10 2
10 5
6 1
2 1
9 4
7 10
5 6
10 7
10 8
5 9
9 7
9 8
4 10
8 9
7 2
2 7
10 1
7 3
6 8
7 6
9 1
6 5
2 4
6 3
2 9
8 10
10 9
8 5
4 1
6 9
2 3
1 3
1 9

output:

931896041

result:

ok single line: '931896041'

Test #7:

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

input:

10 70
5 10
1 8
7 8
6 2
5 7
9 2
4 7
3 7
1 6
3 10
7 9
8 4
7 1
5 2
1 7
4 2
8 3
8 1
3 9
8 2
2 10
4 3
9 10
5 3
3 8
3 4
6 10
4 8
4 5
5 8
9 5
9 6
10 2
10 5
6 1
2 1
9 4
7 10
5 6
10 7
10 8
5 9
9 7
9 8
4 10
8 9
7 2
2 7
10 1
7 3
6 8
7 6
9 1
6 5
2 4
6 3
2 9
8 10
10 9
8 5
4 1
6 9
2 3
1 3
1 9
5 4
1 5
5 1
10 4
10 6

output:

303656759

result:

ok single line: '303656759'

Test #8:

score: 10
Accepted
time: 203ms
memory: 5504kb

input:

15 130
7 10
9 12
4 6
1 10
14 9
4 8
8 9
4 3
15 9
3 9
1 8
2 15
8 4
13 7
3 5
14 13
6 2
14 6
8 3
4 2
8 13
9 2
6 13
12 11
6 4
11 8
15 5
3 8
10 8
15 7
15 6
12 15
8 12
13 9
12 9
8 15
11 6
6 7
10 4
2 8
11 12
7 9
7 12
14 1
5 8
10 9
3 7
7 13
11 9
11 10
1 5
1 3
2 1
2 7
10 1
10 15
7 14
5 6
6 1
15 10
5 15
15 8
5...

output:

717458968

result:

ok single line: '717458968'

Test #9:

score: 10
Accepted
time: 204ms
memory: 5376kb

input:

15 140
7 10
9 12
4 6
1 10
14 9
4 8
8 9
4 3
15 9
3 9
1 8
2 15
8 4
13 7
3 5
14 13
6 2
14 6
8 3
4 2
8 13
9 2
6 13
12 11
6 4
11 8
15 5
3 8
10 8
15 7
15 6
12 15
8 12
13 9
12 9
8 15
11 6
6 7
10 4
2 8
11 12
7 9
7 12
14 1
5 8
10 9
3 7
7 13
11 9
11 10
1 5
1 3
2 1
2 7
10 1
10 15
7 14
5 6
6 1
15 10
5 15
15 8
5...

output:

459157220

result:

ok single line: '459157220'

Test #10:

score: 10
Accepted
time: 205ms
memory: 5504kb

input:

15 150
7 10
9 12
4 6
1 10
14 9
4 8
8 9
4 3
15 9
3 9
1 8
2 15
8 4
13 7
3 5
14 13
6 2
14 6
8 3
4 2
8 13
9 2
6 13
12 11
6 4
11 8
15 5
3 8
10 8
15 7
15 6
12 15
8 12
13 9
12 9
8 15
11 6
6 7
10 4
2 8
11 12
7 9
7 12
14 1
5 8
10 9
3 7
7 13
11 9
11 10
1 5
1 3
2 1
2 7
10 1
10 15
7 14
5 6
6 1
15 10
5 15
15 8
5...

output:

663282473

result:

ok single line: '663282473'