You are not logged in. Please login at www.codechef.com to post your questions!

×

WHAT'S WRONG IN THIS CODE PROBLEM CODE:LIKECS05


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;

}

asked 18 Sep '17, 10:23

pran1234567's gravatar image

1★pran1234567
112
accept rate: 0%

edited 18 Sep '17, 10:40

nice way of thinking!

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

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.

link

answered 18 Sep '17, 13:09

vijju123's gravatar image

5★vijju123 ♦♦
15.4k12066
accept rate: 18%

1

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

(18 Sep '17, 20:08) pran12345671★

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) taran_14076★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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