Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- using namespace std;
- int main() {
- ifstream fin("input.txt");
- ofstream fout("output.txt");
- string str;
- getline(fin, str);
- vector<unsigned long long int> s(str.length(), 0);
- unsigned long long int b, count = 0;
- for (int i = 1; i < str.length(); i++) {
- b = s[i - 1];
- while (b > 0 and str[i] != str[b]) {
- b = s[b - 1];
- }
- if (str[i] == str[b])
- ++b;
- s[i] = b;
- count += b;
- }
- fout << count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement