Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <fstream>
- #include <cstdio>
- #include <vector>
- #include <queue>
- #include <ctime>
- #include <algorithm>
- #include <map>
- #include <string>
- #include <cmath>
- using namespace std;
- typedef long long ll;
- string s;
- vector<ll> h, p, fibv;
- ll l;
- const ll cF = 211;
- ll findLen(ll i, ll x, ll y){
- return x*fibv[i - 1] + y*fibv[i - 2];
- }
- bool is_fib(int i, int x, int y, int len){
- if(len==x+y) return true;
- ll mLen = findLen(i,x,y), hS2 = h[findLen(i-2,x,y)], hS1 = h[findLen(i-1,x,y)], pS = p[findLen(i-1,x,y)+1], hS = h[mLen];
- return (pS*hS2==hS-hS1) && is_fib(i - 1, x, y, findLen(i-1, x, y));
- }
- int main(){
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- getline(cin, s);
- l = s.size();
- fibv.push_back(0);
- fibv.push_back(1);
- p.push_back(0);
- p.push_back(1);
- h.push_back(0);
- h.push_back((int)s[0]-(int)'a'+1);
- for (int i = 1; i <= l; ++i){
- p.push_back(p[i] * cF);
- }
- while (fibv.back() < l) {
- ll i = fibv.size();
- fibv.push_back(fibv[i - 1] + fibv[i - 2]);
- }
- for (int i = 2 ; i <= l; ++i){
- h.push_back(h[i-1] + ((int)s[i-1]-(int)'a'+1)*p[i]);
- }//end of creating hash, power of prime number, fibonacci numbers;
- for (int i = fibv.size() - 1; i >= 4; --i){
- ll fibX = fibv[i-1], fibY = fibv[i-2];
- for (int x = 1; x <= (l/fibX)+1; ++x){
- if (x*fibX>=l) continue;
- if((l - x*fibX) % fibY==0)
- {
- ll y = (l - x*fibX) / fibY;
- if(is_fib(i, x, y, l)){
- cout << i << endl << s.substr(l-y, y) << endl << s.substr(l-x-y, x) << endl;
- return 0;
- }
- }
- }
- }
- cout << 3 << endl
- << s.substr(s.size() - 1, 1) << endl
- << s.substr(0, s.size() - 1) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement