Memory Limit Exceeded...wtf?

programming
Tags: #<Tag:0x00007f2421783380>

#1

Look at my code… dunno why Memory limit exceeded… though working fine.

#include <bits/stdc++.h>
using namespace std ;

vector<vector >help(int n,int Start,bool side){
vector<vector >ans(n,vector(n,0)) ;
if(n==1) {ans[0][0]=Start+1 ;return ans;}
vector<vector >local = help(n-1,Start+2*n-1,!side) ;
if(side){
int i=0 ;
for(i=0;i<n;i++){
ans[0][i]=Start+1+i ;
}
for(int j=1;j<n;j++){
ans[j][n-1]=Start+j+n ;
}
for(i=1;i<n;i++){
for(int j=0;j<n-1;j++){
ans[i][j]=local[i-1][j] ;
}
}
}
else{
int i=0 ;
for(i=n-1;i>=0;i–){
ans[n-1][i]=Start+n-i ;
}
for(int j=n-2;j>=0;j–){
ans[j][0]=Start+n-1-j+n ;
}
for(i=0;i<n-1;i++){
for(int j=1;j<n;j++){
ans[i][j]=local[i][j-1] ;
}
}
}
return ans ;
}
vector<vector > generateMatrix(int A) {
return help(A,0,true) ;
}
int main(){
vector<vector > out = generateMatrix(1000) ;
for(auto i:out){
for(auto j:i) cout<<j<<" " ;
cout<<endl ;
}
return 0 ;
}