ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1423. String Tale

Please help me!I have MLE #8
Posted by Tigran Hakobyan(1 course RAU) 3 Feb 2010 14:12
Here is mu code(C++):
#include <iostream.h>
void sdvig(char a[],int n)
{
    char *y;
    y=new char [n];
    int i,j,total=0;
    for(i=0,j=1;i<n,j<=n;i++,j++)
    {
        if(j==n)
        {
            y[0]=a[n-1];
        }
        else
        {
            y[j]=a[i];
        }
    }
    for(i=0;i<n;i++)
    {
        a[i]=y[i];
    }
}
bool proverka(char x[],char y[],int n)
{
    int total=0,i;
    for(i=0;i<n;i++)
    {
        if(x[i]==y[i])
        {
            total++;
        }
    }
    if(total==n)
        return true;
    return false;
}
const int N=250000;
int main()
{
    char x[N],y[N];
    int n,i,total=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>y[i];
    }
    if(proverka(x,y,n)==true)
    {
        cout<<"0"<<endl;
    }
    else
    {
        while(true)
        {
            total++;
            sdvig(x,n);
            if(proverka(x,y,n)==true)
            {
                cout<<total;
                break;
            }
            else
            {
                if(total==n)
                {
                    cout<<"-1"<<endl;
                    break;
                }
            }
        }
    }
    return 0;
}