Блог пользователя thecortex

Автор thecortex, история, 8 лет назад, По-английски

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.net/contest/711/problem/B Problem Solution: http://codeforces.net/contest/711/submission/20392397

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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