Why i am getting the runtime error at input 80


#1

See my code and please help
vector<vector > Solution::generateMatrix(int A) {
vector<vector > res;
int L=0, R=A-1, T=0, B=A-1;
int dir=0;
int count=1;

while(T<=B && L<=R){
    if(dir==0){
        for(int k=L; k<=R; k++){
            res[T][k]=count;
            count++;
        }
        T++;   
    }
    if(dir==1){
        for(int k=T; k<=B; k++){
            res[k][R]=count;
            count++;
        }
        R--;   
    }
    if(dir==2){
        for(int k=R; k>=L; k--){
            res[B][k]=count;
            count++;
        }
        B--;   
    }
    if(dir==3){
        for(int k=B; k>=T; k--){
            res[k][L]=count;
            count++;
        }
        L++;   
    }
    
    dir = (dir+1)%4;
}

return res;

}


#2

Declare vector as
vector<vector> res(A, vector (A,0));

This removed my runtime error.