Topcoder SRM 707

# | User | Rating |
---|---|---|

1 | Petr | 3325 |

2 | Um_nik | 3284 |

3 | Syloviaely | 3258 |

4 | tourist | 3206 |

5 | anta | 3106 |

6 | fateice | 3099 |

7 | mnbvmar | 3096 |

8 | OO0OOO00O0OOO0O0…O | 3083 |

9 | Radewoosh | 3076 |

10 | HYPERHYPERHYPERC…R | 3071 |

# | User | Contrib. |
---|---|---|

1 | tourist | 183 |

2 | rng_58 | 169 |

3 | csacademy | 163 |

4 | Petr | 159 |

5 | Swistakk | 153 |

6 | lewin | 151 |

7 | matthew99 | 146 |

8 | Errichto | 143 |

9 | Zlobober | 141 |

9 | BledDest | 141 |

Topcoder SRM 707

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/18/2018 03:01:02 (d2).

Desktop version, switch to mobile version.

User lists

Name |
---|

Update: we added one more SRM on Jan 11th and moved the SRM on 14th to 21st.

So we will have 3 SRMs in January! See details: 705, 706, 707

SRM 707 will start in 24 hours!

In second problem I find answer. But I can't restore answer. Can you check my code?

Could people describe some clean solutions for Div 1 250?

I was thinking in terms of BFS initially couldn't get any clue.. Then tried zig zag patterns. No idea at all :(

Is always possible to generate a pattern of the following form:

Thanks! I guess this can be done in

O(N^{2}) too, butO(N^{4}) seems safer to code for TopCoder SRMs.This was my intuition. But how to find the rows and cols required and the zig zag pattern?

Note that the above pattern does not have any up direction moves.

We should also consider the symmetric case where we have to do a pattern with no left direction moves.

Take a 50 * 50 grid with all cells "Safe". Note that the initial shortest path is 98. Handle

K< 98 separately.Then, whenever you are forced to move one step left/up, you increase the shortest path by 2. Thus, if you block enough cells you can make any even number in the range [100, 1000].

For odd

K, use a 49 * 50 grid and repeat the same process.I don't understand. How do u decide where to place the walls?

Suppose your grid is

n*m. You place it in the following order :-(0, 1) (1, 1) (2, 1) ... (

n- 2, 1)(

n- 1, 3) (n- 2, 3) (n- 3, 3) ... (1, 3)(0, 5) (1, 5) (2, 5) ... (

n- 2, 5)and so on....

Basically you're forcing an up movement here and constraints are small enough for you to compute the current shortest path after each addition.

How to prove that this zig-zag approach gives the maximum k, i.e., it gives the maximum number of left steps + up steps?

What do you mean by maximum number? Restating what I said earlier, every "up" movement that you make increases your shortest path by 2, so if

Kis even andn+m- 2 is even, then you will reachKby forcing sufficient number of "up" movements. The case whereKis odd is analogous, just make sure thatn+m- 2 is odd.Here is some code for reference.

## Ignore this comment

Thanks for the reply.

"if you block enough cells you can make any even number in the range [100, 1000]."

Say for a 50 * 50 grid, how to prove that 1000 is the upper bound, and not something higher?

In other words, how to prove max number of "up" movements we can force on a board?

It doesn't. For instance, there's a pattern which can give up to steps but it's too complicated for 250.

Ah I see why I was confused, I didn't pay attention to k <= 1000 constraint. Silly me!

Thanks a lot for your help!

Could you please share with us how to make that pattern?

Solution for Div2 500 and 1000 ? everybody failed Div2 500 .

There must be a mistake in the system test for Div2 500

Ratings are already updated though .

Yes, there seems to a mistake in the test case 3.

Look at the systest, test 121 is wrong, I'm sure

There is an invalid test case in Div2-500

{{"...", ".#.", "..#"}, 4}

Expected (System test output): "DDRR"

Received (My Output): ""

Answer checking result: There exist a solution, but your output is "".

Yes, we are fixing it.

Sorry for the delay.

Update: Fixed now.

Return "Exists" if there is at least one cross on the given board. Otherwise, return "Does not exist". Note that the return value is case-sensitive.

Exist — Exists. I couldn't find bug around 30 minutes. System expected "Exist".

What is the in 13 test cases. I getting segmentation fault...

I got Accepted !!!

Please check my solution (Handle — AM51) . System tests are passing but someone challenged the solution before . Are you also reconsidering the challenges that might have been made with wrong cases ?

How did it affect challenge phase in div2?

What's the correct way to solve Div 1 450?

After applying K multiply operations and L add operations, S can be express in the form:

S*B^{K}+A(B^{p1}+B^{p2}+ ... +B^{pL}) wherepi< =KIterate K from 0 to 64 (or a bit bigger), consider

remain= (T-S*B^{K}) /A, we'll try to express this as sum of power of B. This can be done with a simple greedy.And make sure to check the case B = 0 first. I failed because of this :(

I actually checked the case B = 0 wrongly. I didn't realize you can jump back to 0 if B = 0 -_-

Is there any extra constraint like

p1 >= p2 >= .. >= PL=1

if we consider p1 is largest among them.

It doesn't matter. Just 0 ≤

P_{i}≤Kwill do.approach for Div2 1000 ?

Can anyone help me understand one thing.

How does the following code may result in

segmentation faultfor the following input:`{{".#...", ".#.#.", ".#.#.", ".#.#.", "...#."}, 3000}`

Div2 500I cannot reproduce that problem locally and I get the correct output.

array p has maximal index 2999 and steps variable can be 3000.

Thank you, now passed all systests ;(

Screencast-HackPhase

Can anyone please explain DIV 2 500 problem ?

The way i solved it : Write a recursive function

`bool canSolve(int row,int col,int stepsLeft)`

which tells you if it is possible to reach cell (n-1,m-1) from cell (row,col) in exactlystepsLeftsteps . Transitions are pretty straightforward , just recurse on all 4 adjacent cells .where to stop that recursion when steps left becomes zero ?

Base Case :

`if(stepsLeft == 0) { return row == n-1 && col == m-1 ; }`

can we have this approach 1.

`find the shortest path such that ((K-pathlength)==even_number)`

2.`print that path`

3.`repeat last two consecutive characters (K-pathlength) times .`

How do you find such a shortest path ? K-pathlength can be odd too , if you can find such a path , it should work i think .

Yes, I did exactly that.

ccsnoopy i stucked in the first part , how to efficiently find such path can you please explain ?

Since the graph is unweighted, you can simply do BFS from upper left corner and find the distance on the lower right corner.

in this BFS we should not visit the already visited cell ,am i correct ?

Can anybody explain div2 hard in the context of Min Max flow ? how to reduce the problem to min and max flow ?

Do Solutions submitted for practice problems on TopCoder checked on Full test cases in web arena ?