thecortex's blog

By thecortex, history, 8 years ago, In English

Hello,

I have been spinning my head around this test case for a while now.

Could you please provide the full test case grid?

I thought it was the overflow of the unsigned long long value, but this didn't work.

I thought it was the memory limit, but apparently this wasn't the case.

I tried to mimic the grid by using this form;

0 3 3 3 3 3 3 3 3

And then, my solution outputs the correct value of 3 in the missing cell. (Isn't it?)

Any hints will be appreciated!

Thank you!

Problem Link: http://codeforces.com/contest/711/problem/B Problem Solution: http://codeforces.com/contest/711/submission/20392397

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You are not checking that the columns all add up the same. You are only checking the rows and the diagonals.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you, Quim, but I do already check the columns here;

    for(int j = 0; j < n; j++)
    {
        ull temp_sum = 0;
    
        for(int i = 0; i < n; i++)
        {
           temp_sum += grid[i][j];
        }
    
        if(temp_sum != row_sum)
        {
           cout << -1;
           return(0);
        }
    }
    
    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I meant the rows. You are filling the missing row but not checking that all others have the same value.

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You don't check if the diagonal sums are correct.

As for the post itself, you should learn to calculate roughly how much memory you're using so you know if you've exceeded the limit or not (you only have a very small bidimensional array, so you should be very far from it -- try calculating how much memory you used). You should also learn when overflows are a problem (in this case, no operation will go over 1018, so they can't be).

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you ffao, but I do already check the diagonals;

    if(diag_sum != second_diag_sum)
    {
        cout << -1;
        return(0);
    }

    Thanks for your advice about memory limits and data type ranges.

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      You're checking if the diagonals are the same, but they can be both incorrect.