vovuh's blog

By vovuh, history, 8 years ago, In English

1003A - Polycarp's Pockets

Tutorial
Solution (Vovuh)

1003B - Binary String Constructing

Tutorial
Solution (Vovuh)

1003C - Intense Heat

Tutorial
Solution (PikMike)

1003D - Coins and Queries

Tutorial
Solution (Vovuh)

1003E - Tree Constructing

Tutorial
Solution (Vovuh)

1003F - Abbreviation

Tutorial
Solution (Vovuh)
  • Vote: I like it
  • +39
  • Vote: I do not like it

| Write comment?
»
8 years ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

In E, won't the distance change upon inserting new edges and if yes, how to update the "maximal distance set" efficiently?

  • »
    »
    8 years ago, hide # ^ |
    Rev. 4  
    Vote: I like it +3 Vote: I do not like it

    The previous explanation was wrong, i had understood it now.

    If the distance for some vertex v will change after adding the new vertex, it means that we attach some leaf that increases the diameter of a tree. But it means that we attach a leaf to the vertex w with distw = d, but in this case we already doesn't have the answer.

  • »
    »
    8 years ago, hide # ^ |
    Rev. 5  
    Vote: I like it 0 Vote: I do not like it

    It is possible to prove that there exists such a tree iff n * (k - 2) <= -2 + k * (k - 1) ** (d // 2) for even n and n * (k - 2) <= -2 + k * (k - 1) ** (d // 2) + (k - 2) * (k - 1) ** (d // 2)for odd n. We simply check if conditions above are satisfied and proceed with making the tree or not.

    Edit: also, obviously it must be that n > d as said in the article

    Edit: k = 1 and k = 2 should be treated as special cases

»
8 years ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

My solution to F was to assign an integer to each distinct string (since there's a maximum of 300) while keeping track of lengths for each of these integers and then run a KMP search to find the number of occurrences of each valid subsequence. This solution runs in approximately the same time complexity as the editorial's.

»
8 years ago, hide # |
Rev. 3  
Vote: I like it +7 Vote: I do not like it

There is an O(n) approach in problem C.

code

rough explanation

»
8 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

what wrong in problem F makes a lotta participants output 689 in test 6 instead of 581?

  • »
    »
    8 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Those solutions most likely did not consider more than two segments (only exactly two). The sample tests did not cover this.

»
8 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can anyone explain me the method for Problem C becoz despite several efforts i m unable to figure it out

»
8 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

In problem D my code passed all pretests but it timed out on 27th Case in system testing. No wonder how. Code complexity Q * 32 * 32. Can someone suggest something? Code

  • »
    »
    8 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    unordered_map operations works some more than O(1).

  • »
    »
    8 years ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    U can easily adjust to only Q * 32 operations with a greedy strategy. A complexity has no constants is it. your complexity is O(Q) if you say so. Map operations are O(log) so the number of operations is even worse in your solution. Just adapt to O(Q * log(MAX_VALUE) + N * log(MAX_VALUE)) which actually is O(N * log(VAX_VALUE)) because N and Q constrains are the same. Now to adapt you can just do this:

    the solution
»
8 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Could someone explain why it didn't pass even the pretests? (problem D, WA test 4)

Code

»
8 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
»
8 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

why it times out on test 23?? (problem E) http://mirror.codeforces.com/contest/1003/submission/39989027 but if i assign the values of test 23 and upload the code here it will not time out!!: http://mirror.codeforces.com/contest/959/submission/39989086 why????????????? :(

»
8 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is it possible to solve problem D using Python?

»
8 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why is a random_shuffle performed at the end of the code for problem E?

»
8 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Any O(nlogn) or O(n) method for C?

»
6 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

what is wrong in my code for C ,it's giving the wrong answer on test#4 https://mirror.codeforces.com/contest/1003/submission/85153194

»
6 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem E

My proof that when you attach a new node , d(x) of other nodes won't change.

Let d(x) be the distance of the furthest node from x, now when you attach a new node to node u, and say d(w) changes, then u is the furthest node from w (i.e. d(w) = dist(w,u)), so it means u is the end point of the diameter (d(u) = D, because that's the algorithm we use to find the diameter of a tree, finding the furthest node from a random node), so at that point we simple exit the process.