Demo entry 2668559

MY CODE

   

Submitted by anonymous on Sep 11, 2015 at 11:41
Language: C. Code size: 1.0 kB.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>


int main()
{
    long long n,k,t,i,p,count=0;
    scanf("%lld %lld %lld",&n,&k,&t);
    char a[n+2];
    int long long memo[k];
    for(i=0;i<k;i++)
        memo[i]=-1;
    scanf("%s",a);
    for(i=0;i<n;i++)
    {
        printf("%d : ",i+1,a);puts(a);
        if(a[i]=='1')
        {
            memo[i%k]=i+k;
            continue;
        }
        if(memo[i%k]>=n)
            continue;
        if(memo[i%k]==-1 || memo[i%k]==i)
            p=i+k;
        else
            p=memo[i%k];
        while(p<n && a[p]!='1')
            p+=k;
        printf("  *** %lld ***   ",p);
        if(p<n)
        {
            a[p]='0';
            a[i]='1';
            count+=((i-p)/k);
            memo[i%k]=p+k;
            printf("  *** %lld %lld***   ",memo[i%k],i%k);

        }


        puts(a);
    }
    printf("%s",a);
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).