Submission #226610

# Submission time Handle Problem Language Result Execution time Memory
226610 2020-04-24T13:56:45 Z MKopchev Jump (BOI06_jump) C++14
100 / 100
20 ms 2176 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e2+5;
int n;
int inp[nmax][nmax];

vector<int> dp[nmax][nmax];

vector<int> add(vector<int> a,vector<int> b)
{
    int sz=max(a.size(),b.size());

    vector<int> ret={};

    for(int i=0;i<sz;i++)
    {
        ret.push_back(0);
        if(i<a.size())ret[i]+=a[i];
        if(i<b.size())ret[i]+=b[i];
    }

    ret.push_back(0);
    for(int i=0;i<ret.size()-1;i++)
    {
        ret[i+1]+=ret[i]/10;
        ret[i]=ret[i]%10;
    }

    if(ret.back()==0)ret.pop_back();

    return ret;
}

void print(vector<int> outp)
{
    for(int i=outp.size()-1;i>=0;i--)
        printf("%i",outp[i]);
    printf("\n");
}
int main()
{
    scanf("%i",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            scanf("%i",&inp[i][j]);

    for(int i=n;i>=1;i--)
        for(int j=n;j>=1;j--)
        {
            dp[i][j]={0};
            if(i==n&&j==n){dp[i][j]={1};continue;}

            if(i+inp[i][j]<=n)dp[i][j]=add(dp[i][j],dp[i+inp[i][j]][j]);

            if(j+inp[i][j]<=n)dp[i][j]=add(dp[i][j],dp[i][j+inp[i][j]]);
        }

    print(dp[1][1]);
    return 0;
}

Compilation message

jump.cpp: In function 'std::vector<int> add(std::vector<int>, std::vector<int>)':
jump.cpp:18:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i<a.size())ret[i]+=a[i];
            ~^~~~~~~~~
jump.cpp:19:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i<b.size())ret[i]+=b[i];
            ~^~~~~~~~~
jump.cpp:23:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<ret.size()-1;i++)
                 ~^~~~~~~~~~~~~
jump.cpp: In function 'int main()':
jump.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
jump.cpp:45:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%i",&inp[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 5 ms 640 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 640 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 640 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 6 ms 640 KB Output is correct
15 Correct 8 ms 896 KB Output is correct
16 Correct 14 ms 1536 KB Output is correct
17 Correct 12 ms 1152 KB Output is correct
18 Correct 17 ms 1792 KB Output is correct
19 Correct 16 ms 1408 KB Output is correct
20 Correct 20 ms 2176 KB Output is correct