Due to technical reasons Codeforces may be unavailable on April 21st from 01:00-07:00 (MSK). ×

### yarrr's blog

By yarrr, 5 years ago, ,

Можно ли обсуждать задачи? (а то тишина что-то)

Если да, расскажите пожалуйста как решаются задачи B, E, F.

•
• +32
•

 » 5 years ago, # | ← Rev. 4 →   0 A: Select a node, keep toggling until all of the nodes becomes same color. :) C: DP with state (pos in string, knight1, knight2) D: Exactly as gen said, Ternary Search on time. G: Pure Backtrack. One of our team mates observation was like: if you arrange 36 nodes in 6 x 6 fashion and add edges between adjacent rows, from S to all top row, bottom row to T, then we have only 6^6 ways for going from S to T. which is quite low. We are not sure if this is the worst graph (here to simplify we took 38 nodes) [but there 2^6 also, for 18*2 it makes 2^36 may be] H: loop over all gcd, run a loop over number to see if there is any segment where gcd is that number. its easy. I: I am not sure how many team mate did it, my idea is, you can in O(nlogn) list all divisors for all numbers from 1 to 2e6. Now we know: a + ... + b = (b — a + 1)(a + b) / 2. So see if for each of the divisors of given n, you can find out such a and b. J: DP in two stage. One inter-group another intra-group. Both almost same bitmask DP Unsolved: B: no idea E: I coded DP but later found I overlooked a special permutation, giving WA F: For each number you need to keep track of the number (previous and next) which is not co-prime to it. Say we get a-b pair (a, b are index) if a-b distance is > k ignore. Otherwise, from (k — (b-a)) ~ a add 1 to segment tree and so on. If you just check for 0's in Segtree you will find answer. Not sure if it is correct.
•  » » 5 years ago, # ^ | ← Rev. 5 →   0 I don't understand how you solve H. Could you be more specific?I solved it using divide and conquer with bitset and a little heuristic.But how to solve it in 4 mintes???In I: k=number of consecutive numbersa=starting numberx=the number we want to getx = a*k + k*(k-1)/2Then i just thoughtfor a to 10e6:for k to (while possible):would pass XDand it passed XD
•  » » » 5 years ago, # ^ | ← Rev. 2 →   +3 assume gcd = g, last = 0 for i = 0 to n - 1: if num[i] % g == 0: if last == 0: last = num[i] / g else last = gcd(last, num[i] / g) if last == 1: "g can be gcd" else last = 0 
•  » » 5 years ago, # ^ | ← Rev. 2 →   0 For G you can write a dp to calculate the worst case graph for number of shortest paths. The problem is to create a sequence of positive integers which sum to 34 where the product is maximized.Here is the code in python: N = 34 dp = (N+1) * [(0,)] dp[0] = (1,) for j in range(1,N+1): for i in range(j): dp[j] = max(dp[j], (dp[i][0]*(j-i),)+dp[i][1:]+(j-i,)) print dp[N] The answer: (236196, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)or236196 = 4 * (3 ^ 10)
•  » » » 5 years ago, # ^ |   0 yap, but at the same time, i think to choose/not to choose gold is a factor, but in this complete type graph that factor is 1, since you can always come back. So making a worst graph is a bit difficult, right?
•  » » » » 5 years ago, # ^ |   0 This is the worst case graph for maximizing the number of shortest paths. This would be the worst case runtime for a brute force all shortest paths solution that used Dijkstra's Algorithm to pay back the necessary nodes.There are many graphs you can make that require payback but they reduce the number of shortest paths in the process. So yes, depending on the solution, constructing a worst case graph is hard. :)A solution that brute forces all shortest paths but then brute forces all gold usage on all shortest paths should TLE. I don't think the data is strong enough to break that solution. :(
 » 5 years ago, # |   +5 A relatively complex, but non-hacky solution.1) divide the nodes into levels according to BFS order from node #1; you can merge all levels starting from the one containing node #2 for convenience.2) process levels in ascending order and apply the following dp:dp(i, P) — maximum money we can get on the (shortest) path to i such that the current level of nodes has partitioning P.Partitioning of nodes of a particular level means node arrangement into sets, where all nodes of a set are connected internally and disconnected from nodes in others sets. Two nodes are connected if there exists a path between them in a graph induced by nodes on current and all previous levels minus the nodes we have stolen gold from. Also, mark one or zero sets as special if the nodes in this set are also connected to node #1.knowing dp(i, P), try all edges from i to j on the next level of nodes, and try both stealing and not stealing the money from i, and update dp(j, P) accordingly.3) base case: dp(1, {{1}}) = 04)result: max of dp(2, P) over all P's, where node #2 is in the special set.
 » 5 years ago, # |   0 Hi! I already have an opencup account. I have tried "Sector admin tools -> Ejudge console"(under google translate XD), but didn't find recently contest. Could you tell me where to submit this contest's problem after the contest?
•  » » 5 years ago, # ^ |   0 http://opentrain.snarknews.info/~ejudge/team.cgi?contest_id=9914You can find all the problems from past 2013/2014 constests.
•  » » » 5 years ago, # ^ |   0 Oh, I have entered this page but didn't realize that it is the recently contest's problem…… Thanks a lot!