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 1119. Metro

runtime error
Posted by yakung 9 Mar 2021 09:44
I'm getting runtime error(access violation) on test case three. I don't know where I went wrong. Can anyone please help me?

Here is my code

using namespace std;
#include <iostream>
#include <cmath>
#include<bits/stdc++.h>
long long int n,m;
bool vi[1005][1005], di[1005][1005];
float dp[1005][1005];
#define inf 1e7
float shortest_path(int x, int y){//returns shortest path
    //base case
    if(x==n && y==m) return 0.0;
    if(x>n || y>m) return inf;
    //memorization
    if(vi[x][y]) return dp[x][y];
    //recursive relation
    float a,b,c = 20000.0;
    if(di[x][y]==1){
        a = sqrt(c) + shortest_path(x+1,y+1);//diagonal
        b = inf;
    }

    else
    {
        a = 100.0 + shortest_path(x+1,y);//left
        b = 100.0 + shortest_path(x,y+1);//up
    }

    float ans = min(a,b);
    dp[x][y] = ans;
    vi[x][y] = 1;
    return dp[x][y];
}

int main(){
    cin>>n>>m;
    int k;
    for (int i = 0; i < n*m; ++i)
    {
        for (int j = 0; j < n*m; ++j)
        {
            di[i][j] = 0;
            vi[i][j]=0;
            dp[i][j]=0;
        }
    }
    cin>>k;
    for (int i = 0; i < k; ++i)
    {
        int a,b;
        cin>>a>>b;
        di[a-1][b-1] = 1;
    }

    cout<<round(shortest_path(0,0))<<endl;

}