10307 - Killing Aliens in Borg Maze
Moderator: Board moderators
10307 - Killing Aliens in Borg Maze(+100 hours) (2)
Wow, it seems that the original post crashed! (Time Limit Exceeded x__DDDD). Ok, I wrote the following test case:
20 24
###################
# # # #
# ####A A#### #
# A # # # # A #
# A# # # #A #
# A # #A# # A #
# # ### ### # #
######A A S A A####
#AA A# ### ### # #
# A # #A# # A #
####AAA# # # #A #
# A A# # # # A #
# ####A A#### #
# # # #
# # # #
# #
# AA A #
# #
# #
# A #
# #
# #
# AA A #
###################
Which my program cannot complete, it runs out of memory! :O.
However, the judge gives me wrong answer so my mistake isn't there (or not yet :p). Can anyone break my program??
20 24
###################
# # # #
# ####A A#### #
# A # # # # A #
# A# # # #A #
# A # #A# # A #
# # ### ### # #
######A A S A A####
#AA A# ### ### # #
# A # #A# # A #
####AAA# # # #A #
# A A# # # # A #
# ####A A#### #
# # # #
# # # #
# #
# AA A #
# #
# #
# A #
# #
# #
# AA A #
###################
Which my program cannot complete, it runs out of memory! :O.
However, the judge gives me wrong answer so my mistake isn't there (or not yet :p). Can anyone break my program??
Again, the test case...:
Code: Select all
20 24
###################
# # # #
# ####A A#### #
# A # # # # A #
# A# # # #A #
# A # #A# # A #
# # ### ### # #
######A A S A A####
#AA A# ### ### # #
# A # #A# # A #
####AAA# # # #A #
# A A# # # # A #
# ####A A#### #
# # # #
# # # #
# #
# AA A #
# #
# #
# A #
# #
# #
# AA A #
###################
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
Three things:
1. !!!!!!!! PLESAE REMOVE YOUR CODE FROM THIS THREAD !!!! in other case this thread stops as one before ...
2. My program outputs 90 for your test case ...
3. Please post me last test case (first, which you post)
Maybe any other guru tell what result he does ??
Best regards
DM
1. !!!!!!!! PLESAE REMOVE YOUR CODE FROM THIS THREAD !!!! in other case this thread stops as one before ...
2. My program outputs 90 for your test case ...
3. Please post me last test case (first, which you post)
Maybe any other guru tell what result he does ??
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
With relatively good comments, my code is about 120 lines. I don't expect anyone to read through your code to see what you're trying to do, so instead, explain your algorithm if you want someone to break it..
As for the "correct" solution, there are enough threads that go into it, so do a search and it isn't so bad.
DM:
For the input, I get:
87
As for the "correct" solution, there are enough threads that go into it, so do a search and it isn't so bad.
DM:
For the input, I get:
87
For a while I thought that my program was much better since it gave 79Larry wrote:As for the "correct" solution, there are enough threads that go into it, so do a search and it isn't so bad.
DM:
For the input, I get:
87

I made a mistake cut and pasting the sample input and dropped a space at the end of the line.
After filling the lines so that each one had the expected 20 characters my prog gives 87 too.
So it starts to get intriguing... why does my prog get WA?
Does the judge's input have truncated lines? The problem statement clearly says that the input has y lines each of x characters...
Ciao!!!
Claudio
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
Finally I got it ... (Accepted)
I have a little mistake in my code, when I search aliens on board
So, MST is good approach to solve this question. I agree with Larry - my code has only 130 lines of code, and I think that's enough
My code now output 87 for your input Danifart 
To CDiMa: my code use width and height of plane only for searching aliens on board. So if judge has data i.e.
my program will work fine
It's possible, because perimeter of maze is always closed. I use gets() to read whiole lines, so I don't carre how long are they 
Best regards
DM
I have a little mistake in my code, when I search aliens on board

So, MST is good approach to solve this question. I agree with Larry - my code has only 130 lines of code, and I think that's enough


To CDiMa: my code use width and height of plane only for searching aliens on board. So if judge has data i.e.
Code: Select all
7 3
####
#AS#
####


Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
I just run BFS for every founded alien and start point and find length of shortest path to every other alien/start point - it's possible to optimalize this approach, but I'm to lasy to do this 
if you use BFS, additional memory which is neccessary has only size O(N^2) where N is number of indywiduals on baord
Best regards
DM

if you use BFS, additional memory which is neccessary has only size O(N^2) where N is number of indywiduals on baord
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
Well done, Dominik!!!Dominik Michniewski wrote:Finally I got it ... (Accepted)
Hmmm... Well, I changed my prog so that it handles incomplete lines. Now it gives 87 on the sample of danifart without padding the lines, but still WA for me.Dominik Michniewski wrote:To CDiMa: my code use width and height of plane only for searching aliens on board. So if judge has data i.e.my program will work fineCode: Select all
7 3 #### #AS# ####
It's possible, because perimeter of maze is always closed. I use gets() to read whiole lines, so I don't carre how long are they
Maybe you can post some other input/output that you used?
Ciao!!!
Claudio
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
I'm very sorry , but I onlyuse three inputs: two from sample input and one of danifart - in last one I found my mistake
Maybe helps, if I describe my algorithm (but it's spoiler ... ):
1. read data
2. run bfs for every alien and start point - I find in such way distances between any to aliens or alien and start point
3. sort this distances by length ascending
4. run union algorithm to create MST
5. printf result
Steps 1 and 5 are easy
Best regards
DM

Maybe helps, if I describe my algorithm (but it's spoiler ... ):
1. read data

2. run bfs for every alien and start point - I find in such way distances between any to aliens or alien and start point
3. sort this distances by length ascending
4. run union algorithm to create MST
5. printf result

Steps 1 and 5 are easy

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Born from ashes - restarting counter of problems (800+ solved problems)
I'm doing this also, but I'm looking for an algo that telepatically collects the input. Should improve run times significantlyDominik Michniewski wrote:Maybe helps, if I describe my algorithm (but it's spoiler ... ):
1. read data

I do in a single step both of these, i.e. I store the edges between aliens in distance order.Dominik Michniewski wrote:2. run bfs for every alien and start point - I find in such way distances between any to aliens or alien and start point
3. sort this distances by length ascending
Is this kruskal's? I guess so.Dominik Michniewski wrote:4. run union algorithm to create MST
Here we differ... I printf wrong resultDominik Michniewski wrote:5. printf result

Well, I'll continue testing...
Ciao!!!
Claudio
Well, my mistake was here. Array short by one. If there were 100 aliens my prog ended up giving wrong answers.CDiMa wrote:I do in a single step both of these, i.e. I store the edges between aliens in distance order.Dominik Michniewski wrote:2. run bfs for every alien and start point - I find in such way distances between any to aliens or alien and start point
3. sort this distances by length ascending
Thanks for all who helped.
Ciao!!!
Claudio
10307 making borg 10x faster.
Well, finally I made it. 
My prog solves 10307 in .2 but I see that many people do it 10 times faster, not to mention the fastest one that does it in .006!!!
Runtime of my program is dominated by building the distance array between aliens.
I'm doing a BFS search starting from each alien. Is there a significantly faster way of doing this?
Ciao!!!
Claudio

My prog solves 10307 in .2 but I see that many people do it 10 times faster, not to mention the fastest one that does it in .006!!!

Runtime of my program is dominated by building the distance array between aliens.
I'm doing a BFS search starting from each alien. Is there a significantly faster way of doing this?

Ciao!!!
Claudio