Cod sursă (job #439329)

Utilizator avatar TheodorVlad Paraschiv Theodor Vlad TheodorVlad IP ascuns
Problemă 2sah (clasele 11-12) Compilator cpp | 1,28 kb
Rundă Arhiva de probleme Status evaluat
Dată 26 feb. 2019 11:59:09 Scor 0
#include <iostream>
#include <fstream>
using namespace std;
int a[2001][2001]={0};
int main()
{
    int v,n,i,k;
    ifstream f("p2sah.in");
    ofstream g("p2sah.out");
    f>>v;
    f>>n;
    f>>k;
    if (v==1)
    {
        int p=1;
        for (i=1;i<=k-1;i++)
            {
                p*=3;
                p=p%100003;
            }
        g<<p;

    }
    else
    {
    int j;
    a[1][n+1]=1;
    a[2][n]=1;
    a[2][n+1]=1;
    a[2][n+2]=1;
    int x=n-1;
    int y=n+3;
    for (i=3;i<=n+1;i++)
    {
        a[i][x]=1;
        x--;
        a[i][y]=1;
        y++;
        for (j=x+1;j<=n+1;j++)
        if (j!=n+1)
        {
            a[i][j]=(a[i-1][j-1]+a[i-1][j]+a[i-1][j+1])%100003;
            a[i][2*n+2-j]=a[i][j];
        }
        else
            a[i][j]=(a[i-1][j]+2*a[i-1][j-1])%100003;

    }

    /*for (i=1;i<=n+1;i++)
    {
        for (j=1;j<=2*n+1;j++)
            cout<<a[i][j]<<" ";
        cout<<endl;
    }*/
    i=1;
    j=k;
    int c=0;
    int s=0;
    while (c!=2)
    {
        if (a[i][j]!=0)
            c=1;
        s+=a[i][j];
        i++;
        j=j+2;
        if ((c==1) && (a[i][j]==0))
            c=2;
    }
    g<<s%100003;
    }
    f.close();
    g.close();
    return 0;
}