Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Code for problem strange by cookiedoth
- Generated 25 Jun 2019 at 11.43 P
- ──────▄▌▐▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▌
- ───▄▄██▌█░ВЕЗЁМ▄▀▀▀▄░ГУСЕЙ░░░░░░░
- ───████▌█▄███▀░◐░▄▀▀▀▄░░РАБОТЯГИ░
- ──██░░█▌█░░▄███▀░◐░░▄▀▀▀▄░░░░░░░
- ─██░░░█▌█░░░░▐░▄▀▀▀▌░░░░◐░▀███▄░
- ▄██████▌█▄███▀░◐░░░▌░░░░░▐░░░░░░
- ███████▌█░░░░▌░░░░░▌░░░░░▐░░░░░░
- ███████▌█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▌
- ▀(@)▀▀▀▀▀▀▀(@)(@)▀▀▀▀▀▀▀▀▀▀▀▀▀(@)▀(@)
- ^_^
- -_-
- z_z
- */
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <set>
- #include <map>
- #include <bitset>
- #include <algorithm>
- #include <iomanip>
- #include <cmath>
- #include <ctime>
- #include <functional>
- #include <unordered_set>
- #include <unordered_map>
- #include <string>
- #include <queue>
- #include <deque>
- #include <stack>
- #include <complex>
- #include <cassert>
- #include <random>
- #include <cstring>
- #include <numeric>
- #define ll long long
- #define ld long double
- #define null NULL
- #define all(a) a.begin(), a.end()
- #define debug(a) cerr << #a << " = " << a << endl
- #define forn(i, n) for (int i = 0; i < n; ++i)
- #define sz(a) (int)a.size()
- using namespace std;
- template<class T> int chkmax(T &a, T b) {
- if (b > a) {
- a = b;
- return 1;
- }
- return 0;
- }
- template<class T> int chkmin(T &a, T b) {
- if (b < a) {
- a = b;
- return 1;
- }
- return 0;
- }
- template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) {
- while (begin != end) {
- out << (*begin) << " ";
- begin++;
- }
- out << endl;
- }
- template<class T> void output(T x, ostream& out = cerr) {
- output(x.begin(), x.end(), out);
- }
- void fast_io() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- }
- const int INF = 1e9;
- const int K = 26;
- const int mx = 1010;
- string s;
- int n, val, lcp[mx][mx];
- int gcd(int a, int b) {
- return (b == 0 ? a : gcd(b, a % b));
- }
- void calc_val() {
- int res = 0;
- vector<int> cnt(K);
- for (int i = 0; i < n; ++i) {
- cnt[s[i] - 'a']++;
- }
- for (int i = 0; i < K; ++i) {
- val = gcd(val, cnt[i]);
- }
- }
- void calc_lcp() {
- for (int i = n - 1; i >= 0; --i) {
- for (int j = n - 1; j >= 0; --j) {
- lcp[i][j] = (s[i] == s[j] ? lcp[i + 1][j + 1] + 1 : 0);
- }
- }
- }
- void read() {
- cin >> s;
- n = s.size();
- }
- int best_sum = INF;
- string A, B;
- int put_pref[mx], put_suf[mx];
- bitset<mx> dp[mx];
- void check_pref_suf(int pref, int suf) {
- //cerr << "check_pref_suf " << pref << " " << suf << endl;
- for (int i = 0; i < n; ++i) {
- if (lcp[i][0] >= pref) {
- put_pref[i] = 1;
- }
- if (lcp[i][n - suf] >= suf) {
- put_suf[i] = 1;
- }
- }
- dp[0][0] = 1;
- for (int i = 0; i < n; ++i) {
- if (put_pref[i]) {
- dp[i + pref] |= (dp[i] << 1);
- }
- if (put_suf[i]) {
- dp[i + suf] |= (dp[i] >> 1);
- }
- }
- if (dp[n][0] && chkmin(best_sum, pref + suf)) {
- A = s.substr(0, pref);
- B = s.substr(n - suf, suf);
- }
- }
- void check_sum(int sum) {
- for (int i = 1; i <= sum - 1; ++i) {
- check_pref_suf(i, sum - i);
- }
- }
- void process() {
- for (int i = 1; i <= val; ++i) {
- if (val % i == 0) {
- check_sum(n / i);
- }
- }
- }
- void print() {
- cout << A << " " << B << endl;
- }
- signed main() {
- fast_io();
- read();
- calc_val();
- calc_lcp();
- process();
- print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement