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

×

TIMBERAUCTION OPC WA

Here's my code for the problem timber auction from the IARCS Problem Archive, it gets wrong answer on surprisingly ALL the test cases. It seems to work correctly for all the test cases I've tried. I'm using DP and inclusion-exclusion in order to compute sum...

#include <iostream>
#include <cstdio>
using namespace std;

int main(void)
{
        int n, m, x1, y1, x2, y2, tmp;
        scanf("%d%d", &n, &m);
        int sum[n][m];
        for(int i = 0;i < n;i++)
        {
                for(int j = 0;j < m;j++)
                {
                        scanf("%d", &tmp);
                        if(i == 0 && j == 0)
                        {
                                sum[i][j] = tmp;
                        }
                        else if(i == 0)
                        {
                                sum[i][j] = tmp + sum[i][j-1];
                        }
                        else if(j == 0)
                        {
                                sum[i][j] = tmp + sum[i-1][j];
                        }
                        else
                                sum[i][j] = tmp + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1];
                }
        }
        for(int i = 0;i < n;i++)
        {
                for(int j = 0;j < m;j++)
                {
                        printf("%d ", sum[i][j]);
                }
                printf("\n");
        }
        int c;
        scanf("%d", &c);
        while(c--)
        {
                scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
                int i = x1-1, j =y1-1, k=x2-1, l = y2-1;
                int ans = sum[k][l];
                if(i > 0)
                        ans -= sum[i-1][l];
                if(j > 0)
                        ans -= sum[k][j-1];
                if(i > 0 && j > 0)
                        ans += sum[i-1][j-1];
                printf("%d\n", ans);
        }
}

asked 29 Jan '15, 16:03

nibnalin's gravatar image

6★nibnalin
1611414
accept rate: 0%

The test data is wrong, I've checked.

(29 Jan '15, 18:31) superty3★
3

@nibnalin You are printing out the sum array, did you delete/comment it before submitting?

(29 Jan '15, 18:55) sampritipanda5★

@superty A similar solution which I implemented gets a 100. So I dont think the test data is wrong.

(29 Jan '15, 18:55) sampritipanda5★

Whoops, you are correct, and in fact I have gotten 100 on this as well. I don't know what I'm remembering then. Sorry.

(29 Jan '15, 19:15) superty3★
1

@sampritipanda Facepalm! I forgot to remove those few lines, I don't understand how I can be so foolish. Thanks, anyways...

(30 Jan '15, 09:00) nibnalin6★
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:

×109
×9
×6

question asked: 29 Jan '15, 16:03

question was seen: 655 times

last updated: 30 Jan '15, 09:00