Codeforces Round #338 (Div. 2) C. Running track_codeforces

Source: Internet
Author: User

C. Running Track time limit/test 1 second memory limit per test megabytes input standard input output standard out Put

A Boy named Ayrat lives on Planet AMI-1511. Each inhabitant of the this planet has a talent. Specifically, Ayrat loves running, moreover, just running is isn't enough for him. It dreaming of making running a real art.

The wants to construct the running track with coating T. On planet AMI-1511 the coating of the track are the sequence of colored blocks, where each block is denoted as the small En Glish letter. Therefore, every coating can be treated as a string.

Unfortunately, blocks aren ' t freely sold to non-business customers, but Ayrat and found an infinite number of coatings S. Also , he has scissors and glue. Ayrat is going to buy some coatings s, then cut off from each of them exactly one continuous piece (substring) and glue it To the "end of" of his track coating. Moreover, he could choose to the flip this block before glueing it. Ayrat want's to know the minimum number of coating s he needs to buy in order to get the coating T for his running track. Of course, he also want's to know some way to achieve the answer. Input

The the input contains the string s-the coating is present in the shop. Second line contains the string t-the coating Ayrat wants to obtain. Both strings are non-empty, consist of only small 中文 letters and their length doesn ' t exceed 2100. Output

The should contain the minimum needed number of coatings n or-1 if it ' s impossible to create the desired coati Ng.

If The answer is not-1, then the following n lines should contain two integers XI and yi-numbers of ending blocks in th e corresponding piece. If Xi≤yi then this piece are used in the regular order, and if Xi > Yi piece be used in the reversed. Print the pieces in the order they should is glued to get the string T. Examples input

ABC
CBAABC
Output
2
3 1
1 3
Input
AAABRYTAAA
Ayrat
Output
3
1 1
6 5 8 7

Input
Ami
No
Output
-1
Note

In the "cbaabc" = "CBA" + "abc".

In the second sample: "Ayrat" = "a" + "yr" + "at".

/* *********************************************** AUTHOR:RYC Created time:2016-08-11 Thursday File name:e: \acm\codeforces\338c.cpp language:c++ Copyright 2016 RYC all Rights Reserved *************************************** * #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> # include<algorithm> #include <cmath> #include <queue> #include <list> #include <vector> #
Include<map> #include <stack> using namespace std;
const int maxn=3010;
Char S[MAXN];
Char STR[MAXN];
Char S1[MAXN];
Char TEMP[MAXN];
BOOL VIS[MAXN]; struct node{int l,r;}
ANS[MAXN];
    int main () {scanf ("%s%s", s+1,str+1);
    int Len1=strlen (s+1);
    int Len2=strlen (str+1);
        for (int i=1;s[i];++i) {vis[s[i]-' a ']=true;
    S1[len1-i+1]=s[i];
            for (int i=1;str[i];++i) {if (!vis[str[i]-' a ']) {printf (" -1\n");
        return 0;
    }}s1[len1+1]=0; int Num=0;
        for (int i=1;i<=len2;++i) {int Cnt1=0,l1,l2,cnt2=0;bool sign=false;
            for (int j=i;j<=len2;++j) {temp[cnt1++]=str[j];temp[cnt1]=0;
                if (Strstr (s+1,temp)) {cnt2=cnt1;
            L1=STRSTR (s+1,temp)-S;
                    } else {if (strstr (s1+1,temp)) {sign=true;cnt2=cnt1;
                L2=strstr (s1+1,temp)-s1;
            else break;
        } if (sign) {ans[num].l=len1-l2+1;ans[num].r= (len1-l2+1)-cnt2+1;num++;
        else {ans[num].l=l1;ans[num].r=l1+cnt2-1;num++;
    } i=i+cnt2-1;
    printf ("%d\n", num);
    for (int i=0;i<num;++i) {printf ("%d%d\n", ANS[I].L,ANS[I].R);
return 0;
 }


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.