×

# ZCO problem Little Red Riding Hood

 0 I am trying to solve this problem(http://www.iarcs.org.in/inoi/2013/zco2013/zco2013-1b.php) This is the code I wrote.I have no idea why this is being given a TLE. Can this be improved ? Maximum cost path is definitely an O(n^2+2n) algorithm. Is floodfill the cause of all trouble? The Code: #include #include using namespace std; int map[500][500],tc[500][500]; bool w[500][500]{{false}}; int n,m,a,b,c; void ffill(int r,int c,int l,int k){ if(!w[r][c]){ w[r][c]=true; if(k 0) ffill(r-1,c,l,k+1); if(r < n-1) ffill(r+1,c,l,k+1); if(c > 0) ffill(r,c-1,l,k+1); if(c < n-1) ffill(r,c+1,l,k+1); } } }//A basic flood fill algorithm int main(){ scanf("%d %d",&n,&m); for(int i=0;i

 0 You don't seem to be checking if a square has already been visited in your flood fill. answered 04 Dec '14, 23:59 3★superty 364●1●7 accept rate: 31% I've added the condition for preventing re-evaluation of a square twice(the in the code there in my question),yet still for some test cases the server is marking me WA.Please help. (05 Dec '14, 12:24) http://pastebin.com/CuQqK8ZJ (05 Dec '14, 19:15) superty3★ Can you point out what's the problem in this new code that I've written according to your suggestion (05 Dec '14, 19:31)
 1 Can anyone tell what's wrong with my solution? - http://pastebin.com/VRPVbAW0 I didnt have enough points to ask a new question myself and the olympiad is approaching fast It fails on tasks 1, 3 and 7 answered 11 Nov '15, 12:29 92●3●9 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

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:

×2,212
×733
×427
×399
×247
×37
×24

question asked: 04 Dec '14, 23:41

question was seen: 3,041 times

last updated: 11 Nov '15, 12:31