| Task: | Merkkijonot |
| Sender: | Metabolix |
| Submission time: | 2025-11-13 19:19:03 +0200 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:59:13: error: 'typeof' was not declared in this scope
59 | typeof(tulos) seuraava;
| ^~~~~~
input/code.cpp:62:21: error: 'seuraava' was not declared in this scope
62 | seuraava[tila1] += määrä0 * määrä01;
| ^~~~~~~~
input/code.cpp:68:26: error: 'seuraava' was not declared in this scope
68 | tulos = move(seuraava);
| ^~~~~~~~
input/code.cpp:73:13: error: 'typeof' was not declared in this scope
73 | typeof(kaaret) kaksoiskaaret;
| ^~~~~~
input/code.cpp:77:25: error: 'kaksoiskaaret' was not declared in this scope
77 | kaksoiskaaret[tila0][tila2] += määrä01 * määrä12;
| ^~~~~~~~~~~~~
input/code.cpp:84:27: error: 'kaksoiskaaret' was not declared in this scope
84 | kaaret = move(kaksoiskaaret);...Code
#include <bits/stdc++.h>
using namespace std;
const long MOD = 1'000'000'007;
int n, m;
string s;
typedef unordered_map<uint64_t, uint64_t> määrät_t;
typedef unordered_map<uint64_t, määrät_t> kaaret_t;
kaaret_t kaaret;
void luo_kaaret(uint64_t tila) {
if (kaaret.count(tila)) {
return;
}
for (char c = 'a'; c <= 'z'; ++c) {
uint64_t uusi_tila = 0;
if ((s[0] == c)) {
uusi_tila |= (1ULL << 0);
}
for (int i = 0; i < m-1; ++i) {
if (((tila >> i) & 1) && s[i + 1] == c) {
uusi_tila |= (1ULL << (i + 1));
}
}
if ((tila >> (m-1)) & 1) {
for (int i = 0; i < m; ++i) {
if (s[i] == c) {
uusi_tila |= (1ULL << i);
}
}
}
if (uusi_tila) {
kaaret[tila][uusi_tila] += 1;
if (kaaret[tila][uusi_tila] > 1) {
cerr << "varoitus: moninkertainen kaari tilasta " << tila << " tilaan " << uusi_tila << "\n";
}
luo_kaaret(uusi_tila);
}
}
}
int main() {
cin >> n >> m;
cin >> s;
luo_kaaret(1ULL << 0);
määrät_t tulos;
tulos[1ULL << 0] = 1;
n -= 1; // lähtömerkki on jo asetettu
while (n) {
// Jos tämä bitti kuuluu summaan, edetään näitä kaaria
if (n & 1) {
n -= 1;
typeof(tulos) seuraava;
for (auto& [tila0, määrä0] : tulos) {
for (auto& [tila1, määrä01] : kaaret[tila0]) {
seuraava[tila1] += määrä0 * määrä01;
if (seuraava[tila1] > MOD) {
seuraava[tila1] %= MOD;
}
}
}
tulos = move(seuraava);
}
// Kerrotaan kaaren pituus kahdella
if (n) {
n >>= 1;
typeof(kaaret) kaksoiskaaret;
for (auto& [tila0, mappi] : kaaret) {
for (auto& [tila1, määrä01] : mappi) {
for (auto& [tila2, määrä12] : kaaret[tila1]) {
kaksoiskaaret[tila0][tila2] += määrä01 * määrä12;
if (kaksoiskaaret[tila0][tila2] > MOD) {
kaksoiskaaret[tila0][tila2] %= MOD;
}
}
}
}
kaaret = move(kaksoiskaaret);
}
}
// Voittotilat ovat ne, joissa leima päättyy
long vastaus = 0;
for (auto& [tila, määrä] : tulos) {
if (tila & (1ULL << (m - 1))) {
vastaus += määrä;
if (vastaus > MOD) {
vastaus %= MOD;
}
}
}
cout << vastaus << "\n";
return 0;
}
