QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#181957#4893. Imbalancehos_lyric#10 618ms10524kbC++145.4kb2023-09-17 06:25:392024-07-04 02:01:11

Judging History

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

  • [2024-07-04 02:01:11]
  • 评测
  • 测评结果:10
  • 用时:618ms
  • 内存:10524kb
  • [2023-09-17 06:25:39]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;


int N, K, M;
char S[120];


namespace brute {
vector<int> fs;
int ans;
void dfs(int i) {
  if (i >= K && fs[i - K] == fs[i]) {
    return;
  }
  if (i == N) {
    ++ans;
  } else {
    for (int a = 0; a < 2; ++a) if (i >= M || S[i] - '0' == a) {
      fs[i + 1] = fs[i] + (a ? -1 : +1);
      dfs(i + 1);
    }
  }
}
Mint run() {
  fs.assign(N + 1, 0);
  ans = 0;
  dfs(0);
  return ans;
}
}  // brute


namespace small_k {
bool ban[1 << 20];
Mint run() {
  for (int p = 0; p < 1 << K; ++p) {
    ban[p] = (2 * __builtin_popcount(p) == K);
  }
  vector<Mint> crt(1 << (K-1), 0);
  crt[0] = 1;
  for (int i = 0; i < N; ++i) {
    vector<Mint> nxt(1 << K, 0);
    for (int p = 0; p < 1 << (K-1); ++p) {
      for (int a = 0; a < 2; ++a) if (i >= M || S[i] - '0' == a) {
        nxt[p << 1 | a] += crt[p];
      }
    }
    if (i + 1 >= K) {
      for (int p = 0; p < 1 << K; ++p) if (ban[p]) {
        nxt[p] = 0;
      }
    }
    for (int p = 0; p < 1 << (K-1); ++p) {
      crt[p] = nxt[p] + nxt[p | 1 << (K-1)];
    }
  }
  Mint ans = 0;
  for (int p = 0; p < 1 << (K-1); ++p) {
    ans += crt[p];
  }
  return ans;
}
}  // small_k


int main() {
  for (; ~scanf("%d%d%d", &N, &K, &M); ) {
    if (M) {
      scanf("%s", S);
    } else {
      S[0] = 0;
    }
    
    Mint ans = 0;
    if (K <= 20) {
      ans = small_k::run();
    } else {
      ans = brute::run();
    }
    printf("%u\n", ans.x);
#ifdef LOCAL
if(N<=20){
 const Mint brt=brute::run();
 if(brt!=ans)cerr<<N<<" "<<K<<" "<<M<<" "<<S<<": "<<brt<<" "<<ans<<endl;
 assert(brt==ans);
}
#endif
  }
  return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

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

input:

2 2 0

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

2 2 1
0

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

3 2 0

output:

2

result:

ok 1 number(s): "2"

Test #4:

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

input:

3 2 1
0

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

4 2 0

output:

2

result:

ok 1 number(s): "2"

Test #6:

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

input:

4 2 1
0

output:

1

result:

ok 1 number(s): "1"

Test #7:

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

input:

4 4 0

output:

10

result:

ok 1 number(s): "10"

Test #8:

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

input:

4 4 1
1

output:

5

result:

ok 1 number(s): "5"

Test #9:

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

input:

4 4 2
00

output:

3

result:

ok 1 number(s): "3"

Test #10:

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

input:

4 4 3
101

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

5 2 0

output:

2

result:

ok 1 number(s): "2"

Test #12:

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

input:

5 2 1
1

output:

1

result:

ok 1 number(s): "1"

Test #13:

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

input:

5 4 0

output:

14

result:

ok 1 number(s): "14"

Test #14:

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

input:

5 4 1
0

output:

7

result:

ok 1 number(s): "7"

Test #15:

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

input:

5 4 2
01

output:

3

result:

ok 1 number(s): "3"

Test #16:

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

input:

5 4 3
110

output:

1

result:

ok 1 number(s): "1"

Test #17:

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

input:

17 2 0

output:

2

result:

ok 1 number(s): "2"

Test #18:

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

input:

17 2 0

output:

2

result:

ok 1 number(s): "2"

Test #19:

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

input:

17 10 6
110111

output:

621

result:

ok 1 number(s): "621"

Test #20:

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

input:

17 10 2
11

output:

8413

result:

ok 1 number(s): "8413"

Test #21:

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

input:

18 2 1
1

output:

1

result:

ok 1 number(s): "1"

Test #22:

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

input:

18 2 1
1

output:

1

result:

ok 1 number(s): "1"

Test #23:

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

input:

18 8 5
00010

output:

918

result:

ok 1 number(s): "918"

Test #24:

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

input:

18 8 3
001

output:

3404

result:

ok 1 number(s): "3404"

Test #25:

score: 0
Accepted
time: 6ms
memory: 4416kb

input:

18 16 6
100011

output:

2458

result:

ok 1 number(s): "2458"

Test #26:

score: 0
Accepted
time: 6ms
memory: 4420kb

input:

18 16 8
00101101

output:

548

result:

ok 1 number(s): "548"

Test #27:

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

input:

19 2 1
1

output:

1

result:

ok 1 number(s): "1"

Test #28:

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

input:

19 2 0

output:

2

result:

ok 1 number(s): "2"

Test #29:

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

input:

19 6 2
00

output:

3413

result:

ok 1 number(s): "3413"

Test #30:

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

input:

19 6 1
1

output:

7012

result:

ok 1 number(s): "7012"

Test #31:

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

input:

19 12 10
1010110000

output:

266

result:

ok 1 number(s): "266"

Test #32:

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

input:

19 12 3
111

output:

19234

result:

ok 1 number(s): "19234"

Test #33:

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

input:

19 16 2
10

output:

77876

result:

ok 1 number(s): "77876"

Test #34:

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

input:

19 16 0

output:

301208

result:

ok 1 number(s): "301208"

Test #35:

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

input:

20 2 1
0

output:

1

result:

ok 1 number(s): "1"

Test #36:

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

input:

20 2 0

output:

2

result:

ok 1 number(s): "2"

Test #37:

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

input:

20 10 9
110111000

output:

76

result:

ok 1 number(s): "76"

Test #38:

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

input:

20 10 9
110101110

output:

372

result:

ok 1 number(s): "372"

Test #39:

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

input:

20 14 11
10110110000

output:

207

result:

ok 1 number(s): "207"

Test #40:

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

input:

20 14 7
0011011

output:

3675

result:

ok 1 number(s): "3675"

Test #41:

score: 0
Accepted
time: 75ms
memory: 10416kb

input:

20 20 14
10111010000000

output:

58

result:

ok 1 number(s): "58"

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #42:

score: 10
Accepted
time: 4ms
memory: 3896kb

input:

114 12 11
11010000010

output:

394940507

result:

ok 1 number(s): "394940507"

Test #43:

score: 0
Accepted
time: 4ms
memory: 3816kb

input:

114 12 2
01

output:

60509873

result:

ok 1 number(s): "60509873"

Test #44:

score: 0
Accepted
time: 12ms
memory: 3928kb

input:

114 14 10
1001111011

output:

154687039

result:

ok 1 number(s): "154687039"

Test #45:

score: 0
Accepted
time: 12ms
memory: 3912kb

input:

114 14 5
00100

output:

941826071

result:

ok 1 number(s): "941826071"

Test #46:

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

input:

114 16 10
1011101001

output:

391666362

result:

ok 1 number(s): "391666362"

Test #47:

score: 0
Accepted
time: 45ms
memory: 4132kb

input:

114 16 15
000010011111010

output:

599226561

result:

ok 1 number(s): "599226561"

Test #48:

score: 0
Accepted
time: 171ms
memory: 5120kb

input:

114 18 1
0

output:

167675624

result:

ok 1 number(s): "167675624"

Test #49:

score: 0
Accepted
time: 172ms
memory: 5164kb

input:

114 18 8
11000001

output:

165986235

result:

ok 1 number(s): "165986235"

Test #50:

score: 0
Accepted
time: 610ms
memory: 10524kb

input:

114 20 17
11101000010011010

output:

852476378

result:

ok 1 number(s): "852476378"

Test #51:

score: 0
Accepted
time: 618ms
memory: 10492kb

input:

114 20 13
1101011010000

output:

974712368

result:

ok 1 number(s): "974712368"

Test #52:

score: -10
Wrong Answer
time: 0ms
memory: 3908kb

input:

113 12 8
10101100

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #3:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #84:

score: 0
Wrong Answer
time: 1ms
memory: 3676kb

input:

66 20 5
11001

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #4:

score: 0
Wrong Answer

Test #137:

score: 0
Wrong Answer
time: 1ms
memory: 3688kb

input:

114 20 0

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #5:

score: 0
Skipped

Dependency #2:

0%