### Hasan0540's blog

By Hasan0540, history, 14 months ago, ,

Hello everyone!

The problem set of the 2018 ACM Syrian Collegiate Programming Contest will be available in Codeforces Gym on Nov/23/2018 17:00 (Moscow time).

You will have 12 problems and 5 hours to solve them.

The contest was intended for teams, but I believe it is more interesting for yellow and red coders if they participate individually as they will get to try all the problems.

Your solution should read the input from file, and output to the standard output (stdout).

Problem setters are Motarack, Vendetta., 1am, Light, and Hasan0540.

Thanks to TheDealer, Hiasat, Noureldin, Badry, sqr_hussain, Mohammad Asaad, and Majd Akleh for the help in preparing and testing the problems.

I hope that you will find some interesting problems for you. Any feedback is appreciated!

• +59

 » 14 months ago, # |   +18 Contest was moved to Nov/23/2018 17:00 (Moscow time) as there's another gym contest on Saturday.
•  » » 14 months ago, # ^ |   +4 Thanks for your kindly consideration :)
 » 14 months ago, # |   0 The contest starts in 25 minutes. The first test case is the same as the sample test case. Don't forget to read the input from the required file.Good luck!
 » 14 months ago, # |   +1 how to solve F no. problem of this contest?
•  » » 14 months ago, # ^ | ← Rev. 2 →   +6 Assume that we have an array F such that F[mask] is the number of submissions which fail only on a subset of the tests in mask. We can try all possible permutations using DP in O(2n × n) (similar to the travelling salesman DP solution). When we append a test to the current solution in DP, the number of submissions that didn't fail yet and will run on the new test is F[curMask], so we should add it to the answer of the current state. The mask in our state contains the tests which are not included yet.Check this blog SOS Dynamic Programming [Tutorial] by usaxena95 if you need help in building the array F.
•  » » » 14 months ago, # ^ |   0 Is there an editorial for this contest?
•  » » » 14 months ago, # ^ |   0 Thanks for your help! Now I've learned a new algorithm.
 » 14 months ago, # |   0 How to solve J?
•  » » 14 months ago, # ^ |   0 Greedy algorithm: KAN chooses the first to unlock the groups by priority of earliest second time first. This works because it unlocks something for the other to do while he unlocks other groups (if it doesn't, any other choice also doesn't).
 » 14 months ago, # |   +11 I was a contestant in the onsite competition, I have to say this problemset was really nice and interesting problemset.
 » 14 months ago, # |   0 How to solve H?
•  » » 14 months ago, # ^ |   0 You can always get the minimum answer if the balance between in — out degrees is 0 in every vertex. Also, if it isn't, there's no answer.
 » 14 months ago, # |   0 How to solve C without cheating with Dinic?
•  » » 13 months ago, # ^ |   +3 You can solve by analysing different cases.By Dinics you meant to say that observe answer is always <5 and then create a flow problem which can have flow atmost 5 or something like this and then solve by any flow solution??
•  » » » 13 months ago, # ^ |   0 Oh, I didn't realize the answer is always <5. Thanks.
•  » » » 13 months ago, # ^ |   0 Can you tell what might be the problem if I am getting WA on Test Case 2. I have solved considering different cases.
•  » » » » 13 months ago, # ^ |   0 Check this test: se.
•  » » » » » 13 months ago, # ^ |   0 I have given -1 as output if s and e are adjacent to each other or each of them have a portal next to them.
•  » » » » » » 13 months ago, # ^ |   0 Okay your last submission fails on this e.o#os. Fix it and if it is still wrong, you need to think again about the solution and make sure it handles everything as it doesn't make since to provide many cases in these problems (finding the cases is part of the solution).
•  » » 13 months ago, # ^ |   0 Here's a not-so-smart brute force solution.There are at most 4 optimal places to put a block, namely the closest empty cells on the left/right of S/E. You can then iterate through no more than 2^4 different scenarios (by deciding whether or not to put a block on a candidate block) and check whether S can't reach E.The check function can be implemented with O(n) complexity.
 » 14 months ago, # |   +3 How to solve D?
•  » » 13 months ago, # ^ | ← Rev. 2 →   0 Solved! I made a very stupid mistake.
 » 13 months ago, # |   0 How to solve K?
•  » » 13 months ago, # ^ |   0 Start from highest value to smallest. Assign color = mex of neighbours. dont know proof :P
•  » » » 13 months ago, # ^ |   +26 Nice Solution.I think you can prove it easily. Each has atmost 2 edges with heights greater than it.So mex can be atmost 2. And now for bipartite graph we get always two colors since we always explore the graph in a connected fashion rather than random vertices.
•  » » 13 months ago, # ^ | ← Rev. 2 →   +3 Another solution that is probably less interesting but it's good to know these facts about the constructed graph:The graph is planar, triangulated, and all vertices are boundary vertices. Check the following image:Picking an edge and coloring its ends will split the uncolored vertices into some components, each component will have one vertex with one option, coloring that vertex will leave another vertex with one option... So after picking an edge everything will be uniquely determined unless there's a bridge, in that case you will have more than one option.Implementation: always pick the vertex with the minimum number of remaining options and color it with the minimum available color index (just to make it work on bipartite graphs too). This solution works in O(n) since each vertex will have at most 3 options (no need for a heap or sorting).
 » 13 months ago, # |   +5 Solutions for E,L ?
•  » » 13 months ago, # ^ | ← Rev. 5 →   +18 E:Find three nearest vertices which can propagate to each vertex(based on distance and index as mentioned in question) and then we count all those which has a red as nearest. Similarly we count number of vertices for each blue such that if we remove it will become red also for all pairs of blue similarly. Now we iterate over all pairs of blues and find the most optimal to remove by adding first counts of each blue and pair count. We need to notice that only n pairs of blue are good. rest always contribute zero to second count. So this can be done in O(n) .I think first part of finding three vertices can be done with priority queue similar to dijkstra,
•  » » » 13 months ago, # ^ |   0 ok. Got it. Thanks!