QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#806455#7129. Independent setZi_GaoAC ✓295ms477428kbC++234.1kb2024-12-09 10:54:122024-12-09 10:54:12

Judging History

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

  • [2024-12-09 10:54:12]
  • 评测
  • 测评结果:AC
  • 用时:295ms
  • 内存:477428kb
  • [2024-12-09 10:54:12]
  • 提交

answer

#include<bits/stdc++.h>
// #define ONLINE_JUDGE
#define INPUT_DATA_TYPE int
#define OUTPUT_DATA_TYPE int
inline __attribute((always_inline)) INPUT_DATA_TYPE read(){register INPUT_DATA_TYPE x=0;register char f=0,c=getchar();while(c<'0'||'9'<c)f=(c=='-'),c=getchar();while('0'<=c&&c<='9')x=(x<<3)+(x<<1)+(c&15),c=getchar();return f?-x:x;}void print(OUTPUT_DATA_TYPE x){if(x<0)x=-x,putchar('-');if(x>9)print(x/10);putchar(x%10^48);return;}

template <uint32_t mod>
struct LazyMontgomeryModInt {
  using mint = LazyMontgomeryModInt;
  using i32 = int32_t;
  using u32 = uint32_t;
  using u64 = uint64_t;

  static constexpr u32 get_r() {
    u32 ret = mod;
    for (i32 i = 0; i < 4; ++i) ret *= 2 - mod * ret;
    return ret;
  }

  static constexpr u32 r = get_r();
  static constexpr u32 n2 = -u64(mod) % mod;
  static_assert(mod < (1 << 30), "invalid, mod >= 2 ^ 30");
  static_assert((mod & 1) == 1, "invalid, mod % 2 == 0");
  static_assert(r * mod == 1, "this code has bugs.");

  u32 a;

  constexpr LazyMontgomeryModInt() : a(0) {}
  constexpr LazyMontgomeryModInt(const int64_t &b)
      : a(reduce(u64(b % mod + mod) * n2)){};

  static constexpr u32 reduce(const u64 &b) {
    return (b + u64(u32(b) * u32(-r)) * mod) >> 32;
  }

  constexpr mint &operator+=(const mint &b) {
    if (i32(a += b.a - 2 * mod) < 0) a += 2 * mod;
    return *this;
  }

  constexpr mint &operator-=(const mint &b) {
    if (i32(a -= b.a) < 0) a += 2 * mod;
    return *this;
  }

  constexpr mint &operator*=(const mint &b) {
    a = reduce(u64(a) * b.a);
    return *this;
  }

  constexpr mint &operator/=(const mint &b) {
    *this *= b.inverse();
    return *this;
  }

  constexpr mint operator+(const mint &b) const { return mint(*this) += b; }
  constexpr mint operator-(const mint &b) const { return mint(*this) -= b; }
  constexpr mint operator*(const mint &b) const { return mint(*this) *= b; }
  constexpr mint operator/(const mint &b) const { return mint(*this) /= b; }
  constexpr bool operator==(const mint &b) const {
    return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);
  }
  constexpr bool operator!=(const mint &b) const {
    return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);
  }
  constexpr mint operator-() const { return mint() - mint(*this); }
  constexpr mint operator+() const { return mint(*this); }

  constexpr mint pow(u64 n) const {
    mint ret(1), mul(*this);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  constexpr mint inverse() const {
    int x = get(), y = mod, u = 1, v = 0, t = 0, tmp = 0;
    while (y > 0) {
      t = x / y;
      x -= t * y, u -= t * v;
      tmp = x, x = y, y = tmp;
      tmp = u, u = v, v = tmp;
    }
    return mint{u};
  }

  constexpr u32 get() const {
    u32 ret = reduce(a);
    return ret >= mod ? ret - mod : ret;
  }

  static constexpr u32 get_mod() { return mod; }
};

const int mod=1000'000'007;
using mint=LazyMontgomeryModInt<mod>;

int n,m;
mint dp[5000010][2][12],C[12][12];
char s[5000010];

int main(){
	#ifndef ONLINE_JUDGE
	freopen("name.in", "r", stdin);
	freopen("name.out", "w", stdout);
	#endif

    register int u,i,j,a;
    register mint res=0;
    n=read();m=read();

    scanf("%s",s);

    for(u=n;u;--u){
        if(u*2+1<=n){ for(i=0;i<=m&&dp[u*2][1][i]!=0;++i) for(j=0;i+j<=m;++j) dp[u][0][i+j]+=dp[u*2][1][i]*dp[u*2+1][1][j];
        }else if(u*2<=n) memcpy(dp[u][0],dp[u*2][1],(m+1)*sizeof(mint));
        else dp[u][0][0]=1;

        if(s[u-1]=='0'){
            if(u*2+1<=n){ for(i=0;i<=m&&dp[u*2][0][i]!=0;++i) for(j=0;i+j<m;++j) dp[u][1][i+j+1]+=dp[u*2][0][i]*dp[u*2+1][0][j];
            }else if(u*2<=n) memcpy(dp[u][1]+1,dp[u*2][0],m*sizeof(mint));
            else dp[u][1][1]=1;
        }
        for(i=0;i<=m;++i) dp[u][1][i]+=dp[u][0][i];
    }

    for(i=0;i<=m;++i) for(j=1,C[i][0]=1;j<=i;++j) C[i][j]=(C[i-1][j]+C[i-1][j-1]);
    for(i=1;i<=m;++i) res+=dp[1][1][i]*C[m-1][i-1];
    print(res.get());

	#ifndef ONLINE_JUDGE
	fclose(stdin);
	fclose(stdout);
	#endif
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 2
00

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 3
0101010101

output:

26

result:

ok 1 number(s): "26"

Test #3:

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

input:

10 3
0000100000

output:

110

result:

ok 1 number(s): "110"

Test #4:

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

input:

10 3
0001000000

output:

117

result:

ok 1 number(s): "117"

Test #5:

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

input:

10 3
0010000001

output:

86

result:

ok 1 number(s): "86"

Test #6:

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

input:

10 3
0100000000

output:

115

result:

ok 1 number(s): "115"

Test #7:

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

input:

10 3
0010000000

output:

118

result:

ok 1 number(s): "118"

Test #8:

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

input:

10 3
1011001000

output:

45

result:

ok 1 number(s): "45"

Test #9:

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

input:

10 3
0000011001

output:

49

result:

ok 1 number(s): "49"

Test #10:

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

input:

10 3
0000010011

output:

48

result:

ok 1 number(s): "48"

Test #11:

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

input:

10 3
0100100101

output:

35

result:

ok 1 number(s): "35"

Test #12:

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

input:

10 3
0000000011

output:

72

result:

ok 1 number(s): "72"

Test #13:

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

input:

1000 10
0000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

876560614

result:

ok 1 number(s): "876560614"

Test #14:

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

input:

1000 10
0000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000010000000000000000000000000000000100000000000000010000000000000000000000001000000010000001000000000000000000000000000000000000000000000000000000000000...

output:

45119364

result:

ok 1 number(s): "45119364"

Test #15:

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

input:

1000 10
1100000010000000000010011100000000001000001101001010010000100100001000000000001010010100100000001001000000000000000010000010000001010000000000100000100000000000010100010000110000010010001000000000001000001000000000010001011010000000100100000000001010001110000010000000000000000000000000000000...

output:

460336587

result:

ok 1 number(s): "460336587"

Test #16:

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

input:

1000 10
0000000100000001000010001100000000000100000011000000000110100111000000100000000001000000000100100100010010011000010000010010001000100100000000000000100000100000010000000100000000000100001000000000000000000010000000001000010001000000010010000000000000000000100001000100000001000010100100011010...

output:

48086189

result:

ok 1 number(s): "48086189"

Test #17:

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

input:

1000 10
0010000000001000000001011000000000000000000000000000000000000001000010000001011000000000000000000000000000000010000010010000010000100001000001000000110000000000000100000000000000001001000000001000000001010000001001000000000000000000000000000000000010000000000010000001100001000000000100000110...

output:

512493587

result:

ok 1 number(s): "512493587"

Test #18:

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

input:

1000 10
0000000010000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000...

output:

412295689

result:

ok 1 number(s): "412295689"

Test #19:

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

input:

1000 10
0000100111000011101000000000010110000001100001100100000000000000001001000000010000100000010000010000000000100000000001000001000000010000000000110000100001000000001010010000000000110101100000100000101000110100001001000000101000000000000000010000001000100000000100001001010010010001000000000000...

output:

518455593

result:

ok 1 number(s): "518455593"

Test #20:

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

input:

1000 10
0000000100000000001000000000000000000000000000000001000000000000000010000000000010000000000000000000000000100100010000000110000000000000000000000000000010000000000000100000000100000000000000000000100010000000000100000000010010001000000000000000000000000000000000000000000000000000001000010000...

output:

430339412

result:

ok 1 number(s): "430339412"

Test #21:

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

input:

1000 10
0000110010000000000010101001010000100010010110000100001000100001000000000010000100000011100000000000010100001000000000000000100000100001100000001000000111100000100101001000000000000000001000001000100000000010000000001000001000000000001000000000000000001000100100001100100000011010001000000011...

output:

348316472

result:

ok 1 number(s): "348316472"

Test #22:

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

input:

1000 10
0000100000000010000000000000000000000000000000000001000010000010001010010000000000000000100100100100101101001001010000100000000000100000000000000100001010011100000001000000000010000000001000001001000001010001001000000010000000110000010000000000000000000101000001100000100000100000001010001000...

output:

213483490

result:

ok 1 number(s): "213483490"

Test #23:

score: 0
Accepted
time: 44ms
memory: 100592kb

input:

1000000 10
1000000000100011011000001001000100000111000100001001000000000000000000000010100000010000000000000001100110010100011010001000100100001101010010101100001100100110001100010001000000000000011000001000010100000100000110001101000000000100110000100000100001000010000001000010000100001000000011110...

output:

476845308

result:

ok 1 number(s): "476845308"

Test #24:

score: 0
Accepted
time: 52ms
memory: 99252kb

input:

1000000 10
0000000000000000000000000000000001000000100000000000000000000000000000000000000000000100000000010000000010000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000100001010000000000000000000000000000000000000000000000000100000010000100000010...

output:

774002748

result:

ok 1 number(s): "774002748"

Test #25:

score: 0
Accepted
time: 47ms
memory: 100076kb

input:

1000000 10
0000000000000000000001000000010000010010100110110001000100010000100000000111001000000000000001010000101000000000011000101000100000000000000000000000110010000000111001010000000000010000110000000100100000000001001001001001000010010001010000000000000000100001000000000000001100000100000000000...

output:

160255662

result:

ok 1 number(s): "160255662"

Test #26:

score: 0
Accepted
time: 55ms
memory: 100148kb

input:

1000000 10
0000000010000000000000100000000000000010000100001000000000000000000000100000100000000000000000000000000000100000000000000000011000000011000000001010000000000011000010111000010000000000000000000010000000000000000010000000000000000000010000010000100000001000000000000000010001000001000000000...

output:

707886122

result:

ok 1 number(s): "707886122"

Test #27:

score: 0
Accepted
time: 42ms
memory: 99660kb

input:

1000000 10
0100100000000000000000000000000100000000000100100000000000010000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000011000000000000000000000000000010000000000000000000000100000100000000000000000000000000000000000010000100000010000000000000000...

output:

979709914

result:

ok 1 number(s): "979709914"

Test #28:

score: 0
Accepted
time: 264ms
memory: 477420kb

input:

5000000 10
0000000000000000001000000000010000001000000000000000001000010000000000000000000000000000000000000000000000000000000000100000000000000000010001000000100000000000011000000000000000000001000000001000000000000000000000000000000000000000000000000001000000000000000000000001000100010000000001000...

output:

285627161

result:

ok 1 number(s): "285627161"

Test #29:

score: 0
Accepted
time: 258ms
memory: 477288kb

input:

5000000 10
0000000000000000000010000000010000000010000000000000000000000000000000000000000000000010000000000000000000000000001000000000000100000000000010000000000000000011000000000000000000000000000000000000000000000000000000000000000000010000000000000000010100100000010000000000000000000010000000000...

output:

303121972

result:

ok 1 number(s): "303121972"

Test #30:

score: 0
Accepted
time: 295ms
memory: 477368kb

input:

5000000 10
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

840451042

result:

ok 1 number(s): "840451042"

Test #31:

score: 0
Accepted
time: 290ms
memory: 477280kb

input:

5000000 10
0001001100000000000000000000000001000000000000010000000011000000000000000000000000010000000000000000000000000001001010000000100000000000000100000000000010101000010000010001000100000100000000000101000000010000000001010010000000000010100000000010000011000000000000000000000000000001000000000...

output:

5553929

result:

ok 1 number(s): "5553929"

Test #32:

score: 0
Accepted
time: 266ms
memory: 477428kb

input:

5000000 10
0000000000000000010000000000000000000000010000000000001000010100010010000110000000000000100010000000000000100000000000000010000000000000100000000000001100000000000000000000000000000100000000000000000000000000001010000000000100100000000000000000000000001000010100100011000000000000000000001...

output:

996917998

result:

ok 1 number(s): "996917998"