Submission details
Task:Merkkijonot
Sender:Yytsi
Submission time:2025-11-09 22:51:30 +0200
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3, 4, 5details
#2ACCEPTED0.01 s2, 3, 4, 5details
#3ACCEPTED0.01 s1, 2, 3, 4, 5details
#4ACCEPTED0.01 s1, 2, 3, 4, 5details
#5ACCEPTED0.01 s1, 2, 3, 4, 5details
#6ACCEPTED0.01 s1, 2, 3, 4, 5details
#7--1, 2, 3, 4, 5details
#8ACCEPTED0.01 s1, 2, 3, 4, 5details
#9ACCEPTED0.03 s1, 2, 3, 4, 5details
#10ACCEPTED0.01 s1, 2, 3, 4, 5details
#11ACCEPTED0.02 s2, 3, 4, 5details
#12--2, 3, 4, 5details
#13--2, 3, 4, 5details
#14--2, 3, 4, 5details
#15--2, 3, 4, 5details
#16--2, 3, 4, 5details
#17--2, 3, 4, 5details
#18--2, 3, 4, 5details
#19--3, 4, 5details
#20--3, 4, 5details
#21--3, 4, 5details
#22--3, 4, 5details
#23--3, 4, 5details
#24--3, 4, 5details
#25--3, 4, 5details
#26--3, 4, 5details
#27--4, 5details
#28--4, 5details
#29--4, 5details
#30--4, 5details
#31--4, 5details
#32--4, 5details
#33--4, 5details
#34--4, 5details
#35--5details
#36--5details
#37--5details
#38--5details
#39--5details
#40--5details
#41--5details
#42--5details

Code

#pragma GCC optimize("Ofast","unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int n, m;
string tape;

static inline uint64_t hash64(const string& s) {
  uint64_t h = 1469598103934665603ull;
  for (unsigned char c : s) {
    h ^= (uint64_t)c;
    h *= 1099511628211ull;
  }
  return h;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin>>n>>m;

  cin>>tape;

  int len = n - m + 1;
  if (len <= 0) return cout << "0\n", 0;

  string arr;
  for (int i = 0; i < n; i++) arr += ".";

  stack<string> st;
  st.push(arr);

  unordered_set<uint64_t> vis, comp;
  vis.reserve(303030);
  vis.max_load_factor(0.7);
  comp.reserve(303030);
  comp.max_load_factor(0.7);
  vis.insert(hash64(arr));

  while (!st.empty()) {
    string cur_arr = st.top();
    st.pop();

    bool f = true;
    for (char c : cur_arr) {
      if (c == '.') {
        f = false;
        break;
      }
    }
    if (f) {
      comp.insert(hash64(cur_arr));
      continue;
    }

    for (int i = 0; i < len; i++) {
      string next_arr = cur_arr;
      bool diff = false;
      for (int j = 0; j < m; j++) {
        int pos = i + j;
        if (next_arr[pos] == '.') {
          next_arr[pos] = tape[j];
          diff = true;
        }
      }

      if (!diff) continue;

      uint64_t hh = hash64(next_arr);

      if (!vis.count(hh)) {
        vis.insert(hh);
        st.push(next_arr);
      }
    }
  }

  cout << comp.size() << "\n";
  return 0;
}

Test details

Test 1

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
1 1
a

correct output
1

user output
1

Test 2

Group: 2, 3, 4, 5

Verdict: ACCEPTED

input
20 20
ssxfykmuzljmwgyvldnu

correct output
1

user output
1

Test 3

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
20 10
aaaaaaaaaa

correct output
1

user output
1

Test 4

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
20 10
aabbbaaaab

correct output
1532

user output
1532

Test 5

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
20 10
aabbacbdca

correct output
1542

user output
1542

Test 6

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
20 10
ztknszhrby

correct output
3261

user output
3261

Test 7

Group: 1, 2, 3, 4, 5

Verdict:

input
20 1
a

correct output
1

user output
(empty)

Test 8

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
20 10
aabbbbbbba

correct output
1689

user output
1689

Test 9

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
20 8
abxabyab

correct output
8619

user output
8619

Test 10

Group: 1, 2, 3, 4, 5

Verdict: ACCEPTED

input
20 10
ababababab

correct output
509

user output
509

Test 11

Group: 2, 3, 4, 5

Verdict: ACCEPTED

input
100 50
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
1

user output
1

Test 12

Group: 2, 3, 4, 5

Verdict:

input
100 50
bbaaabbbbbabbbbabababababbbaab...

correct output
511493117

user output
(empty)

Test 13

Group: 2, 3, 4, 5

Verdict:

input
100 50
addabbbbbadddccadcabaacbbbaabd...

correct output
618572722

user output
(empty)

Test 14

Group: 2, 3, 4, 5

Verdict:

input
100 50
rrdumiqrjewanjplbyvkaytbcyzbyl...

correct output
35126431

user output
(empty)

Test 15

Group: 2, 3, 4, 5

Verdict:

input
100 1
a

correct output
1

user output
(empty)

Test 16

Group: 2, 3, 4, 5

Verdict:

input
100 50
aabbbbbbbbbbbbbbbbbbbbbbbbbbbb...

correct output
460606355

user output
(empty)

Test 17

Group: 2, 3, 4, 5

Verdict:

input
100 23
aybabtuxaybabtuyaybabtu

correct output
342213037

user output
(empty)

Test 18

Group: 2, 3, 4, 5

Verdict:

input
100 50
ababababababababababababababab...

correct output
775006564

user output
(empty)

Test 19

Group: 3, 4, 5

Verdict:

input
1000 50
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
1

user output
(empty)

Test 20

Group: 3, 4, 5

Verdict:

input
1000 50
bbabaabbabbbaaaaaaaaaababaabbb...

correct output
911592620

user output
(empty)

Test 21

Group: 3, 4, 5

Verdict:

input
1000 50
cacabdddcbdadabdcbdddbdddbaccb...

correct output
12869296

user output
(empty)

Test 22

Group: 3, 4, 5

Verdict:

input
1000 50
tqoyadbshyehwcwaxbtbsqtaswkyet...

correct output
741984969

user output
(empty)

Test 23

Group: 3, 4, 5

Verdict:

input
1000 1
a

correct output
1

user output
(empty)

Test 24

Group: 3, 4, 5

Verdict:

input
1000 50
aabbbbbbbbbbbbbbbbbbbbbbbbbbbb...

correct output
599950419

user output
(empty)

Test 25

Group: 3, 4, 5

Verdict:

input
1000 23
aybabtuxaybabtuyaybabtu

correct output
548809016

user output
(empty)

Test 26

Group: 3, 4, 5

Verdict:

input
1000 50
ababababababababababababababab...

correct output
765799780

user output
(empty)

Test 27

Group: 4, 5

Verdict:

input
1000000 50
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
1

user output
(empty)

Test 28

Group: 4, 5

Verdict:

input
1000000 50
bbaababbaaabbabababbaaaaaabbaa...

correct output
514073453

user output
(empty)

Test 29

Group: 4, 5

Verdict:

input
1000000 50
aabccabbbbabccabcdcdadbcdccdac...

correct output
438094288

user output
(empty)

Test 30

Group: 4, 5

Verdict:

input
1000000 50
yzfzimxrxfukhlkrtaylohyuqkupsn...

correct output
905445077

user output
(empty)

Test 31

Group: 4, 5

Verdict:

input
1000000 1
a

correct output
1

user output
(empty)

Test 32

Group: 4, 5

Verdict:

input
1000000 50
aabbbbbbbbbbbbbbbbbbbbbbbbbbbb...

correct output
280596224

user output
(empty)

Test 33

Group: 4, 5

Verdict:

input
1000000 23
aybabtuxaybabtuyaybabtu

correct output
268144314

user output
(empty)

Test 34

Group: 4, 5

Verdict:

input
1000000 50
ababababababababababababababab...

correct output
655244665

user output
(empty)

Test 35

Group: 5

Verdict:

input
1000000000 50
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

correct output
1

user output
(empty)

Test 36

Group: 5

Verdict:

input
1000000000 50
abbbaabbaaaaabbbbabbabbaaaaaba...

correct output
911059863

user output
(empty)

Test 37

Group: 5

Verdict:

input
1000000000 50
cbabbcaadabbcabbdbdabbbcccbdca...

correct output
994268014

user output
(empty)

Test 38

Group: 5

Verdict:

input
1000000000 50
pehyicejeninplaczwezhahmbhwfwi...

correct output
837165971

user output
(empty)

Test 39

Group: 5

Verdict:

input
1000000000 1
a

correct output
1

user output
(empty)

Test 40

Group: 5

Verdict:

input
1000000000 50
aabbbbbbbbbbbbbbbbbbbbbbbbbbbb...

correct output
114333489

user output
(empty)

Test 41

Group: 5

Verdict:

input
1000000000 23
aybabtuxaybabtuyaybabtu

correct output
628064772

user output
(empty)

Test 42

Group: 5

Verdict:

input
1000000000 50
ababababababababababababababab...

correct output
802946327

user output
(empty)