# WHAT'S WRONG IN THIS CODE PROBLEM CODE:LIKECS05

## using namespace std;

int main()
{

``````int n,m,e=0,g=0,r=0,y=0;
cin>>n>>m;
int a[n][n];
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
``````

``````		a[i][j]=0;
}
}
while(m--)
{
int type,idx,c;
cin>>type;
switch(type)
{
case 1 :
cin>>idx;
cin>>c;
for(int i=1;i<=n;i++)
{
if(a[idx][i]!=c+1)
{
if(a[idx][i]>2)
{
a[idx][i]=a[idx][i];
}
else
a[idx][i]=a[idx][i]+c+1;
}
}
break;

case 2	:      cin>>idx;
cin>>c;
for(int i=1;i<=n;i++)
{
if(a[i][idx]!=c+1)
{
if(a[i][idx]>2)
{
a[i][idx]=a[i][idx];
}
else
a[i][idx]=a[i][idx]+c+1;
}

}
break;

case 3 :		cin>>idx;
cin>>c;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i+j==idx)
{
if(a[i][j]!=c+1)
{
if(a[i][j]>2)
{
a[i][j]=a[i][j];
}
else
a[i][j]=a[i][j]+c+1;
}

}
}
}
break;
}
}

for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(a[i][j]==0)
e++;
else if(a[i][j]==1)
g++;
else if(a[i][j]==2)
r++;
else
y++;
}
}

cout<<e<<g<<r<<y;
``````

}

1 Like
``````int a[n][n];
``````

N is upto {10}^{5}, so size of this array becomes {10}^{10}. This requires memory in GB. Meaning, you are crossing the memory limit for the problem. You cannot declare a 2-D array this large.

what can i use instead of arrays to store large data??

1 Like

There’s an alternative solution, which does not involve storing such large amount of data…

With present technology, creating such array will require GBs of data…

Why not learn something new, faster and efficient way of solving such problem from editorial…

Hope that helps…

nice way of thinking!

//