Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define min(a, b) (((a) < (b)) ? (a) : (b))
- void prefix(char s[], int p[]){
- unsigned long long n = strlen(s);
- for (unsigned int i = 1; i<n; ++i){
- int j = p[i - 1];
- while (j > 0 && s[i] != s[j]) {
- j = p[j - 1];
- }
- if (s[i] == s[j]) {
- p[i] = j + 1;
- }
- else {
- p[i] = j;
- }
- }
- }
- int main(void) {
- char s1[1000001];
- char s2[1000001];
- char s[2000002];
- int p[2000002] = {0};
- //int p[20000] = {0};
- scanf("%1000000s", s1);
- scanf("%1000000s", s2);
- strcpy(s, s1);
- strcat(s, s2);
- prefix(s, p);
- if (p[strlen(s)-1] > min(strlen(s1), strlen(s2))){
- printf("%lu ", min(strlen(s1), strlen(s2)));
- }
- else{
- printf("%d ", p[strlen(s)-1]);
- }
- strcpy(s, s2);
- strcat(s, s1);
- int p1[2000002] = {0};
- //int p1[20000] = {0};
- prefix(s, p1);
- if (p1[strlen(s)-1] > min(strlen(s1), strlen(s2))){
- printf("%lu", min(strlen(s1), strlen(s2)));
- }
- else{
- printf("%d", p1[strlen(s)-1]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement