In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1.
In the second sample, we perform the following steps:
Initially we place a single slime in a row by itself. Thus, row is initially 1.
Then, we will add another slime. The row is now 1 1. Since two rightmost slimes have the same values, we should replace these slimes with one with value 2. Thus, the final state of the board is 2.
In the third sample, after adding the first two slimes, our row is 2. After adding one more slime, the row becomes 2 1.
In the last sample, the steps look as follows:
- 1
- 2
- 2 1
- 3
- 3 1
- 3 2
- 3 2 1
- 4
AC-code:
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n,i,j,sum,s[100005];
scanf("%d",&n);
memset(s,0,sizeof(s));
sum=0;
for(i=1,j=0;i<=n;i++,j++)
{
s[j]++;
for(;j>=1;j--)
{
if(s[j]==s[j-1])
{
s[j-1]++;
s[j]=0;
}
else
break;
}
}
printf("%d",s[0]);
if(j==0)
{
printf("\n");
}
else
{
for(i=1;s[i]!=0;i++)
printf(" %d",s[i]);
printf("\n");
}
return 0;
}