#include <cstdio> #include <string> #include <iostream> #include <vector> #include <algorithm> #include <cstring> char s[37]; std::string c[100]; int b[100]; int N; int cN = 0; std::vector<std::pair<int, bool>> v[100]; bool sprawdz() { for (int i = 0; i < cN; i++) { if (memcmp(c[i].c_str(), s+(b[i]-1), c[i].size()) == 0) return false; } return true; } long long oblicz() { long long ret = 0; while (s[N] == 0) { ret += sprawdz(); s[0]++; for (int i = 0; s[i] == 2; i++) { s[i] = 0; s[i + 1]++; } } return ret; } int main() { scanf("%d ", &N); if (N > 30) { printf("KREDENS"); return 0; } std::string s; std::getline(std::cin, s); int t = (int) s.size(); bool shouldM = false; for (int i = 0; i < t; i++) { if (s[i] == ')') cN++; else if (s[i] == '~') shouldM = true; else if (s[i] == 'x') { v[cN].push_back({0, !shouldM}); shouldM = false; } else if (s[i] >= '0' && s[i] <= '9') { v[cN][v[cN].size() - 1].first *= 10; v[cN][v[cN].size() - 1].first += s[i] - '0'; } } for (int i = 0; i < cN; i++) { std::sort(v[i].begin(), v[i].end()); } for (int i = 0; i < cN; i++) { b[i] = v[i][0].first; for (auto& it : v[i]) { c[i] = c[i] + (char) it.second; } } printf("%lld", oblicz()); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #include <cstdio> #include <string> #include <iostream> #include <vector> #include <algorithm> #include <cstring> char s[37]; std::string c[100]; int b[100]; int N; int cN = 0; std::vector<std::pair<int, bool>> v[100]; bool sprawdz() { for (int i = 0; i < cN; i++) { if (memcmp(c[i].c_str(), s+(b[i]-1), c[i].size()) == 0) return false; } return true; } long long oblicz() { long long ret = 0; while (s[N] == 0) { ret += sprawdz(); s[0]++; for (int i = 0; s[i] == 2; i++) { s[i] = 0; s[i + 1]++; } } return ret; } int main() { scanf("%d ", &N); if (N > 30) { printf("KREDENS"); return 0; } std::string s; std::getline(std::cin, s); int t = (int) s.size(); bool shouldM = false; for (int i = 0; i < t; i++) { if (s[i] == ')') cN++; else if (s[i] == '~') shouldM = true; else if (s[i] == 'x') { v[cN].push_back({0, !shouldM}); shouldM = false; } else if (s[i] >= '0' && s[i] <= '9') { v[cN][v[cN].size() - 1].first *= 10; v[cN][v[cN].size() - 1].first += s[i] - '0'; } } for (int i = 0; i < cN; i++) { std::sort(v[i].begin(), v[i].end()); } for (int i = 0; i < cN; i++) { b[i] = v[i][0].first; for (auto& it : v[i]) { c[i] = c[i] + (char) it.second; } } printf("%lld", oblicz()); return 0; } |