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

×

adakng Problem

1
1

// Can some one please look into my code snippet for the ADAKNG Problem // and point out why my code is not accepted . The code is in C++ //Thank you.

`#include <iostream> using namespace std;

int main() { int t,r,c,k; int y; int dr,ur,fc,bc; / dr = lower_most_row ur = upper_most_row fc = right_most_column bc = left_most_column / int no_of_squares;

dr = 0;
fc = 0;
ur = 8;
bc = 8;

cin>>t;

while(t--)
{
    cin>>r>>c>>k;

    for(y=k;y>=0;y--)
    {
        if( (1 <= (r+y)) && ((r+y) <= 8) )//if the row exists
            if((r+y) > dr)// if the new value is lower than current row
                dr = (r+y);

        if( (1 <= (r-y)) && ((r-y) <= 8) )// if the row exists
            if((r-y) < ur)// if the new value is higher than current row
                ur = (r-y);

        if( (1 <= (c+y)) && ((c+y) <= 8) )//if the column exists
            if((c+y) > fc)// if the new value is more right than current column
                fc = (c+y);

        if((1 <= (c-y)) && ((c-y) <= 8))//if the column exists
            if((c-y) < bc)// if the new value is more left than current column
                bc = (c-y);

    }

    no_of_squares = (dr - ur + 1) * (fc - bc + 1);
    cout<<no_of_squares<<"\n";
}
return 0;

} `

asked 04 Feb, 23:07

koder_1998's gravatar image

0★koder_1998
101
accept rate: 0%

Please prefer to share your submission/code link, and explain your logic in the body of question.

(05 Feb, 00:12) vijju123 ♦♦5★

One mistake that I found is that you have initialised dr, ur, fc, bc outside the t loop. They need to be reinitialised everytime for different test cases. Fix this. If it still doesn't work and there are more errors, comment below and I'll try to find them.

Hope this helps :)

link

answered 05 Feb, 02:56

akashbhalotia's gravatar image

5★akashbhalotia
865214
accept rate: 10%

1

Thank you Akash. Your Suggestion really worked out.

(06 Feb, 18:13) koder_19980★
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:

×20

question asked: 04 Feb, 23:07

question was seen: 91 times

last updated: 06 Feb, 18:13