Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TL 1st group https://informatics.mccme.ru/mod/statements/view3.php?id=18805&chapterid=113098#1
- # include <set>
- # include <string>
- # include <iostream>
- # include <algorithm>
- using namespace std;
- void gen_st(string &s, set<string> &st) {
- size_t n = s.length();
- for (size_t i = 0; i < n; i++) {
- string st_cur;
- st_cur += s[i];
- st.insert(st_cur);
- for (size_t j = i + 1; j < n; j++) {
- st_cur += s[j];
- st.insert(st_cur);
- }
- }
- }
- void gen_posl(string &s, set<string> &posl, string cur_s, size_t k) {
- if (k == s.length()) {
- if (cur_s.length() > 0){
- posl.insert(cur_s);
- }
- } else {
- gen_posl(s, posl, cur_s, k + 1);
- cur_s += s[k];
- gen_posl(s, posl, cur_s, k + 1);
- }
- }
- int32_t check_st(string &s) {
- set<string> st;
- set<string> posl;
- string s_func = "";
- gen_st(s, st);
- gen_posl(s, posl, s_func, 0);
- if (st.size() == posl.size()) {
- return 1;
- }
- else {
- return 0;
- }
- }
- int main() {
- string s;
- int32_t count = 0;
- set<string>check_set;
- cin >> s;
- gen_st(s, check_set);
- for (auto i = check_set.begin(); i != check_set.end(); i++) {
- string cur = *i;
- count += check_st(cur);
- }
- cout << count;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement