Блог пользователя DBradac

Автор DBradac, история, 10 лет назад, По-английски

Join us this Saturday on the 7th round of this year's COCI!

Click to see where the coding begins in your timezone.

We can discuss the problems here after the contest.

  • Проголосовать: нравится
  • +53
  • Проголосовать: не нравится

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I just tried to register but I'm getting "You're not allowed to log in from this location." Is it not an open contest?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Reminder: less than 2 hours left.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

I wonder what happened to the author of the second task. Why the footnote is so sarcastically?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Firstly, I scared input of 50 :D

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +32 Проголосовать: не нравится

The problem statement of second task is so long it's disgraceful.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

How to solve B (80) problem ?

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +4 Проголосовать: не нравится

    Look at divisors of 2N.

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    Hint: sum of l,l+1,...,r-1,r is equal to (l+r)/2.0*(r-l+1)
    try iterating over every possible value of (r-l+1)

  • »
    »
    10 лет назад, скрыть # ^ |
    ← Rev. 4  
    Проголосовать: нравится +7 Проголосовать: не нравится

    You can solve in

    Easy understandable code

    You will understand from that :

    sum of 2 adj. numbers: m + (m + 1) = 2m + 1

    sum of 3 adj. numbers: m + (m + 1) + (m + 2) = 3m + 3

    sum of 4 adj. numbers: m + (m + 1) + (m + 2) + (m + 3) = 4m + 6 .. etc..

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve C? I used bitmasks for 40pts.

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +14 Проголосовать: не нравится

    This might be overkill.

    Let's denote the amount of a-s, b-s and c-s Slavko has for some some suffix of Mirko's string as sa, sb, sc. Also denote the amount of a-s, b-s and c-s in the suffix as ma, mb, mc. Then that suffix is solvable with the given letters iff the maximum flow of the following graph is sa + sb + sc:

    Now we can iterate over Mirko's string and choose the lexicographically smallest character so that the remaining string is still solvable with the remaining letters.

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Task Igra: implement an O(n) function to answer "is it possible to arrange a valid string if we have (a1, b1, c1) free characters against (a2, b2, c2) already placed characters (notice that a1 + b1 + c1 = a2 + b2 + c2). To do it you can iterate over what part of a1 goes to b2, and then all the rest if fixed and can be checked with some ifs.

    Now you can iterate over each character of answer string and try to place a, then b, then c and check if it is correct. It is O(n2), obviously. By the way, the function is some kind of maxflow, so it can even be solved in nearly constant time, making O(n) operations total.

  • »
    »
    10 лет назад, скрыть # ^ |
    ← Rev. 3  
    Проголосовать: нравится 0 Проголосовать: не нравится

    You can just pick the letter greedily, checking if choosing such letter and you can still have a valid string afterwards.

    e.g. if you choose 'a' at pos i, you need to make sure no. of 'b' in Slavko[i + 1 .. n] <= (a — 1) + c, no. of 'c' in Slavko[i + 1..n] <= (a — 1) + b. you can do this O(1). where a, b, c are the number of letter that Mirko still have.

    So overall time complexity is O(N).

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +30 Проголосовать: не нравится

How to solve 140pts?

»
10 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

I wonder why the limits for third task are so small. Isn't there an O(n * alpha^2) solution?

UPD: seems like my solution is wrong

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

how to solve F?

I can solve it only for 64 points with a weird Gauss Elimination but I have no idea how to do it for max.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Is it just me or COCI's are becoming harder and harder?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

What's an expected value?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Fourth problem (120) may fail because of recursion?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How long does it normally take for COCI results to be final? It's my first time competing in a round.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

Azret was the first place in 6th round but he scored 130 in this contest. Isn't it weird?

»
10 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

I got a solution for problem D that got TLE on 2 last testcases. How can I improve it?

First, treat the scale as a binary tree (left child = left beam, right child = right beam, weight = leaf node). There will be maximumly 3n nodes in this tree.

Call dpu the smallest sum (in binary form) for a balanced subtree in vertex u. Then:

We got a O(n2) solution now. How can we make this faster?

Since dpu is now a string, multiply by 2 also mean add character '0' to the end of the string. So, with careful implementation using pointer, "assigning" value for all dp states will take totally O(n). What about time needed to compare the strings from two children? It's in the worst case (The tree look like an segment tree with value of all leafs equal each other). So we got a solution.

My code

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    My solution was saving the values and the exponential of two considered that the answer is one of the node * power of 2. This give a linear solution. The last two were hard so I luckily got 12th by solving first 4 problems lol.

  • »
    »
    10 лет назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится +3 Проголосовать: не нравится

    Sorry if this is stupid, but how to prove correctness of the DP for an internal(scale) node? I mean if we have scale with children having weights a and b(a ≤ b) we'd have to add b - a weight to the left child, but how do you know that it can be done while maintaining the current balance within that subtree? Wouldn't it be required for b - a to be divisible by 2height where height =  height of the node from the bottom?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My solution for D got just 54pts. I think my approach is correct —

For all the weights, I found the wt such for maximum value — w[i]/pow(2,level[i]). Answer is concatenation of binary representation of wt and level of wt times '0'.

also I took care of the fact that level can go upto 10^6.

My Code

Where am I wrong?

»
10 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

Am I the only one, who thought, that in the 4th problem you are only allowed to add weights to the existing weights (in other words, to the leaves of the tree)? Got only 54 points during the contest because of that and full score in the analysis mode when I decided to leave this assumption alone (and I believe, that my first assumption is way more intuitive).

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

How to solve the 5th problem?

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    Sketch of the solution (I am an author of the problem):

    Take any 3 noncolinear points and bring them all to the [5, +inf] x [5, +inf] quadrant of the plane. It can be seen that such series of moves exists if you observe the tiling of the plane by parallelogram generated from those 3 points. Now, you can just use BFS to find shortest series of moves to bring those 3 points to that part of the plane. Since coordinates are small you can check all possibilities and see that in worst case this takes around 1200 moves.

    Last, you can see that after you have points A, B in quadrant [5, +inf] x [5, +inf] you can move any other point C to first quadrant with just one move.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Form problem D, it seems like I had to use linear diophantine and solve it using extended euclidean algo but I have no idea was it is an just gave up :(