Codeforces Extra-terrestrial Intelligence

#include<bits/stdc++.h>
using namespace std;

int dis[110];

int main()
{
    ios_base::sync_with_stdio(false);
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n;
    while(cin >> n)
    {
        int d , keep=0 , len=0;
        char x;
        bool f=false , extra=false;

        for(int i=0; i<n; i++)
        {
            cin >> x;

            if(x == '1')
            {
                if(!f)
                {
                    dis[i] = i;
                    keep = i;
                    f=true;
                }

                else
                {
                    keep = i - keep;
                    len++;
                    dis[len] = keep;
                    keep = i;
                    if(len > 1)
                    {
                        if(dis[len] != dis[len-1]) extra=true;
                    }
                }
            }
        }

        if(extra) cout << "NO\n";
        else cout << "YES\n";
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number