Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official. ×

Hasan0540's blog

By Hasan0540, history, 4 weeks ago, In English,

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!

 
 
 
 
  • Vote: I like it  
  • +59
  • Vote: I do not like it  

»
4 weeks ago, # |
  Vote: I like it +18 Vote: I do not like it

Contest was moved to Nov/23/2018 17:00 (Moscow time) as there's another gym contest on Saturday.

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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!

»
3 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

how to solve F no. problem of this contest?

  • »
    »
    3 weeks ago, # ^ |
    Rev. 2   Vote: I like it +6 Vote: I do not like it

    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.

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Is there an editorial for this contest?

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thanks for your help! Now I've learned a new algorithm.

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve J?

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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).

»
3 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

I was a contestant in the onsite competition, I have to say this problemset was really nice and interesting problemset.

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve H?

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve C without cheating with Dinic?

  • »
    »
    9 days ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    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??

    • »
      »
      »
      9 days ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Oh, I didn't realize the answer is always <5. Thanks.

»
2 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

How to solve D?

»
9 days ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve K?

  • »
    »
    9 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Start from highest value to smallest. Assign color = mex of neighbours.

    dont know proof :P

    • »
      »
      »
      9 days ago, # ^ |
        Vote: I like it +26 Vote: I do not like it

      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.

  • »
    »
    9 days ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    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).

»
9 days ago, # |
  Vote: I like it +5 Vote: I do not like it

Solutions for E,L ?

  • »
    »
    9 days ago, # ^ |
    Rev. 5   Vote: I like it +18 Vote: I do not like it

    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,