412.md (3819B)
1 Source: https://codeforces.com/blog/entry/11756 2 3 [412A - Poster](/contest/412/problem/A "Coder-Strike 2014 - Round 1") 4 5 One of the optimal solutions is the following. If *k* - 1 ≤ *n* - *k* then firstly let's move ladder to the left by *k* - 1 positions. After that we will do the following pair of operations *n* - 1 times: paint *i*-th symbol of the slogan and move the ladder to the right. In the end we will paint the last symbol of the slogan. If *k* - 1 > *n* - *k* then we will move the ladder to the right by *n* - *k* positions. After that we will also paint symbol and move the ladder to the left. Our last action will be to paint the first symbol of the slogan. Total number of sought operations is *min*(*k* - 1, *n* - *k*) + 2·*n* - 1. 6 7 [412B - Network Configuration](/contest/412/problem/B "Coder-Strike 2014 - Round 1") 8 9 In this task you should sort array in descending order and print *k*-th element. Due to the weak constraints you could also solve the problem in the following manner. Let's brute *ans* — the value of answer and calculate how many computers already have Internet's speed not less than *ans*. If there are not less than *k* such computers then the answer is acceptable. Let's find the maximum among acceptable answers and it will be the sought value. 10 11 [412C - Pattern](/contest/412/problem/C "Coder-Strike 2014 - Round 1") 12 13 Let's find the answer symbol-by-symbol. Let's consider *i*-th symbol. If there are two different symbols differ from '?' on *i*-th positions in the given strings then we must place '?' on *i*-th position in the answer. If there are '?' on *i*-th positions in all string then we can write any symbol. Obviously, it is better to write not '?' but any letter, 'x' for example. Lastly we should consider the case when there are only '?' and one the same letter on *i*-th positions. In this case we should find this letter and put it to the answer. 14 15 [412D - Giving Awards](/contest/412/problem/D "Coder-Strike 2014 - Round 1") 16 17 Let's build sought permutation by adding employee one-by-one. Let's we already define the order of the first *k* employees: *a*1, *a*2, ..., *a**k*. Let's place *k* + 1-th after *a**k*-th. If *a**k*-th employee owe money to *k* + 1-th then we will swap their positions (and will get permutation *a*1, *a*2, ..., *a**k* - 1, *k* + 1, *a**k*). If *a**k* - 1-th employee also owe money to *k* + 1-th then we will also swap their positions and so on. If all first *k* employees owe money to *k* + 1-th then *k* + 1-th employee will be placed first in permutation. This algorithm has time complexity *O*(*m*), where *m* is the number of the debt relationships. 18 19 [412E - E-mail Addresses](/contest/412/problem/E "Coder-Strike 2014 - Round 1") 20 21 Let's consider position *i* such, that *s**i* = '@'. We are going to calculate the number of such substrings that are correct addresses and the symbol '@' in them is *s**i*. Let's go to the left from *i* until we find '@' or '.' — the symbols that aren't allowed to be to the left of '@'. Let's calculate *cnt* how many letters on the segment we went through. This letters can be the first symbols of the correct addresses. Let's now move to the right of *i* while considered symbol is letter or digit. If we stopped and the string is over or the following symbol is '@' or '_' then there aren't correct addresses. If the following symbol is '.' then let's go to the right of it while the considered symbols are letters. The correct address can finish in every such position, so we should add *cnt* to the answer. In the described solution "move" means "brute by cycle for". We can do this because we will go through each symbol not more than 2 times. Total time complexity is *O*(*n*).