Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define forn(i, a, n) for(int i = a; i < n; ++i)
- #define f first
- #define s second
- #define pb push_back
- #define mp make_pair
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <queue>
- #include <functional>
- #include <map>
- //#pragma comment(linker, "/STACK:6777237" )
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- ll lastb = 0;
- struct boar
- {
- ll pos = 0;
- map<char, boar> chi;
- void operator = (ll a)
- {
- pos = a;
- }
- ll finder(string& word) // left, right
- {
- ll result = 0;
- char c = word[pos];
- if (word.size() == pos && chi.size() == 0) return 0;
- if (word.size() == pos && chi.size() > 0) return 2;
- if (chi[c].pos == 0)
- {
- result = 1;
- chi[c] = pos + 1;
- }
- return max((chi[c].finder(word)), result);
- }
- };
- string s;
- ll cursor, outp;
- boar dict;
- map<string, ll> stash;
- bool norm(char c)
- {
- return(c >= 'a' && c <= 'z');
- }
- string cut()
- {
- string res;
- while (cursor < s.size() && !norm(s[cursor]))
- {
- cursor++;
- outp++;
- }
- while (cursor < s.size() && norm(s[cursor]))
- {
- res += s[cursor];
- cursor++;
- }
- while (cursor < s.size() && !norm(s[cursor]))
- {
- cursor++;
- outp++;
- }
- return res;
- }
- void counter()
- {
- while (cursor < s.size())
- {
- string work = cut();
- ll b = dict.finder(work);
- string pat = "";
- outp += work.size();
- //if(work.size())
- ll pus = 2;
- forn(i, 0, work.size())
- {
- pat += work[i];
- if (b == 2)
- {
- stash[pat]++;
- }
- if (stash[pat] == 1)
- {
- pus--;
- }
- if (b == 1)
- {
- stash[pat]++;
- }
- }
- outp += min(pus, (ll)0);
- }
- }
- int main(void) {
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- getline(cin, s);
- while (s.size() != 0)
- {
- outp++;
- cursor = 0;
- counter();
- s.clear();
- getline(cin, s);
- }
- cout << outp;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement