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 1012. K-based Numbers. Version 2

Who can tell me the reason? WA on test 8
Posted by felomid 15 Aug 2018 08:22
this is my code G++
#include<bits/stdc++.h>
using namespace std;

int n,k;


void pl(int a[],int b[],int c[])
{
  for(int i=1;i<=210;i++)
    {
    c[i]+=a[i]+b[i];
    c[i+1]+=c[i]/10;
    c[i]%=10;
  }
}

void cheng(int a[],int x)
{
  for(int i=1;i<=210;i++)
    {
    a[i]*=x;
    a[i]+=(a[i-1]/10);
    a[i-1]%=10;
  }
}

int f[2000][222];

int main()
{
    scanf("%d%d",&n,&k);
    f[0][0]=0;
    f[1][0]=1;
    f[1][1]=k-1;
    for(int i=2;i<=n;i++)
    {
        pl(f[i-2],f[i-1],f[i]);
         cheng(f[i],k-1);
    }
    for(int i=1;i<=210;i++)
    {
    f[n][i]+=f[n-1][i];
    f[n][i+1]+=f[n][i]/10;
    f[n][i]%=10;
  }
    int h=221;
    while(!f[n][h])    h--;
    for(int i=h;i>=1;i--)
        printf("%d",f[n][i]);
 return 0;
 }