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

×

# TIMBERAUCTION OPC WA

 0 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 #include 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 6★nibnalin 161●1●5●15 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) @superty A similar solution which I implemented gets a 100. So I dont think the test data is wrong. (29 Jan '15, 18:55) 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 community wiki:
Preview

### Follow this question

By Email:

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

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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: 670 times

last updated: 30 Jan '15, 09:00