×

# include<iostream>

## 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;


}

112
accept rate: 0%

nice way of thinking!

(18 Sep '17, 21:25) 1★

 0 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. answered 18 Sep '17, 13:09 15.4k●1●20●66 accept rate: 18% 1 what can i use instead of arrays to store large data?? (18 Sep '17, 20:08) 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... :) (18 Sep '17, 20:14)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,719
×2,363
×1,912
×311
×37
×19
×15
×8

question asked: 18 Sep '17, 10:23

question was seen: 328 times

last updated: 18 Sep '17, 21:25