186.md (6412B)
1 Source: https://codeforces.com/blog/entry/4488 2 3 No problem was specially taken from "Wikipedia". For me it's really hard to understand, that problem "B" was there. 4 5 **A (Div 2).** (Idea : [Gerald](/profile/Gerald "Master Gerald"), realization : [Aksenov239](/profile/Aksenov239 "Candidate Master Aksenov239"), code : [1670635](/contest/186/submission/1670635 "Submission 1670635 by Aksenov239")) 6 7 If the lengths of 2 strings aren't equal — that means "NO". We try to find the positions in strings, where chars are different. If there 1 or more than 2 such positions — "NO". After that we swap 2 characters in the first string, and check for their equality. 8 9 **B (Div 2).** (Idea : [Aksenov239](/profile/Aksenov239 "Candidate Master Aksenov239"), realization : [Aksenov239](/profile/Aksenov239 "Candidate Master Aksenov239"), code : [1670637](/contest/186/submission/1670637 "Submission 1670637 by Aksenov239")) 10 11 1. We can see, that we can do all in integers, because k is integer number of percent. 12 2. For each dwarf we should find his optimal strategy — to check 2 strategies with speed. 13 3. We should sort them. 14 15 **A (Div 1).** (Idea : [Aksenov239](/profile/Aksenov239 "Candidate Master Aksenov239"), realization : [Aksenov239](/profile/Aksenov239 "Candidate Master Aksenov239"), code : [1652592](/contest/185/submission/1652592 "Submission 1652592 by Aksenov239")) Let's propose, that after the *i*-th year, there is *x* triangles up and *y* triangles down. After another iteration we can see, that amount of triangles became — 3*x* + *y* up and *x* + 3*y* down. Let's see the difference between them: at the *i*-th it's *x* - *y* and at the *i* + 1-th — it's (3*x* + *y*) - (*x* + 3*y*) = 2 * (*x* - *y*). We can see, that difference between amount of triangles grown up by 2. Because on the *i*-th year the difference became 2*i* and all amount of triangles is 4*i*. We can see, that on the *i*-th year the number of our triangles is . That can be computed by modulo p using the fast-power algorithm. 16 17 **B (Div 1).** (Idea : [Aksenov239](/profile/Aksenov239 "Candidate Master Aksenov239"), realization : [Aksenov239](/profile/Aksenov239 "Candidate Master Aksenov239"), code : [1652597](/contest/185/submission/1652597 "Submission 1652597 by Aksenov239")) This problem was made by my love to inequalities. :-)! The answer for this problem is . 18 19 Prove: . (This is AM-GM inequality. [Link for whom don't know it.](http://www.artofproblemsolving.com/Wiki/index.php/AM-GM)) 20 21 The equality becomes only, when . 22 23 And you should check on zeroes. If *a* = *b* = *c* = 0 — you can choose any good answer — *x* + *y* + *z* ≤ *S*. 24 25 **C (Div 1).** No comments. :-)! 26 27 **D (Div 1).** (Idea : [Aksenov239](/profile/Aksenov239 "Candidate Master Aksenov239"), realization : [cerealguy](/profile/cerealguy "International Master cerealguy"), [Gerald](/profile/Gerald "Master Gerald"), [Aksenov239](/profile/Aksenov239 "Candidate Master Aksenov239"), code : [1652604](/contest/185/submission/1652604 "Submission 1652604 by Aksenov239")) 28 29 This is number theory problem. 30 31 I'm trying to explain it step by step: 32 33 1) Let's prove, that LCD is maximum 2. 34 35 Let . Squaring both sides we get , but we want to . This means, that *d* can be only 2. 36 37 2) Let's make this lenghty product simplier. 38 39 . 40 41 We can count this by modulo *p* fast, and divide it by 2*r* - *l*, if *k* is odd. 42 43 3) There is many interesting things in this solution. 44 45 Firstly, it doesn't work, when *p* = 2 — but it can easily done by you. 46 47 The other problem is harder, what if , this means that for each *i* ≥ *l* : , and this mean, 48 that for each *i* ≥ *l* : *k*2*i* + 1 ≡ *p*2. And the product by modulo *p* is equal to 2*r* - *l* + 1. 49 50 E (Div. 1) (Idea : [Aksenov239](/profile/Aksenov239 "Candidate Master Aksenov239"), relization : [cerealguy](/profile/cerealguy "International Master cerealguy"), code : [1652611](/contest/185/submission/1652611 "Submission 1652611 by Aksenov239")) 51 52 This problem wasn't taken to ROI, because of that I gave it here. This is pretty hard problem. I can't now realize, what [cerealguy](/profile/cerealguy "International Master cerealguy") wrote, but his solution is *O*(*nlogn*) — without binary search. For me it's quite hard to understand, because my first solution was with binary search. And there were solutions, that has a worse asymptothic, but they run faster. 53 54 Because of that I can only give you key ideas, that can help you. (afterwards you can see the code of [cerealguy](/profile/cerealguy "International Master cerealguy")) 55 56 Ideas: 57 58 1. Let's find for each person the nearest subway point for them. It can be done in nlogn with use of segment tree or something else. 59 2. We can see, that if one person goes to subway, the others, which distance to subway is smaller, can go to subway too — it doesn't affect the answer. Because of that we sort all persons by their distanse to subway. 60 3. The area of the person, where he can come in *t* seconds, is romb. And we can intersect all rombes in *O*(*n*) — the intersection is like rectangle. 61 4. Let's make the first intersection. When nobody goes to subway. We get a rectangle. 62 5. The main idea, that for this rectangle — the nearest subway becomes always the same. We go throught people in sorted order, we can fast recalculate this small rectangle — and because of that we can fast recalculate the answer. 63 64 And we get a solution in *O*(*nlogn*) time. Ta-dams. 65 66 Thank you all for your attention. I'm deeply sorry about the problem "C".