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

Автор awoo, история, 7 лет назад, По-русски

1207A - There Are Two Types Of Burgers

Идея: BledDest

Разбор
Решение (Roms)

1207B - Square Filling

Идея: BledDest

Разбор
Решение (BledDest)

1207C - Gas Pipeline

Идея: adedalic

Разбор
Решение (adedalic)

1207D - Number Of Permutations

Идея: Roms

Разбор
Решение (Roms)

1207E - XOR Guessing

Идея: adedalic, Neon, BledDest

Разбор
Решение (BledDest)

1207F - Remainder Problem

Идея: BledDest

Разбор
Решение (BledDest)

1207G - Indie Album

Идея: adedalic

Разбор
Решение (PikMike)
  • Проголосовать: нравится
  • +119
  • Проголосовать: не нравится

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

[DELETED]

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

In solution for C) editorial says that: If s[pos]=1 then we have to stay on the height 2, but in the sample test 1 8 2 5 00110010 It is optimal to go to height 1, after index 3, where s[3] = 1, and s[4] = 0 (as shown in the problem figure). What am I missing here?

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

    The "s" array in the editorial corresponds to intervals (so s[3] corresponds to the height of the interval (3, 4)), but the dp array "d" corresponds to the height at specific x-values.

    In other words, because s[3] = 1, the road needs to be at height 2 at x=4, meaning that d[4][0] doesn't exist. s[4] = 0 instead means that d[5][0] and d[5][1] are both OK.

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

Огромное спасибо за решения! Каждый раз удивляюсь своему навыку всё усложнять ...

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

I didn't get the 2nd query of F ? What sum is supposed to calculate ?

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

During contest, after solving first 5 problems, spent 1 hour working on problem F looking for a solution which was faster than O(n^(3/2)) because I assumed, incorrectly, that O(n^(3/2)) cannot pass... I even designed an O(n^(4/3)) algorithm to solve a simpler version of the problem where all the numbers are fixed from the beginning and never modified. (The solution is similar to the solution in the editorial except that the value of K is n^(2/3) instead of sqrt(n)). I then spent all the time trying to improve my algorithm to support modification to the sequence...

Honestly, I also felt that problem E was much easier than problem C and D.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Can anyone explain more elaborately :
»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

IN ques.D for counting of cnt1,given is cnt1=c1!*c2*!..cn! my doubt is while calculating c1! ,it is not necessary that the corrsponding elements in the another column will be all different and give different permutations..so we must divide it by those factorials..

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

An online solution to problem G :

We build the suffix automaton for the trie which is given, and then we build a segment tree for every node (endpos set) . For a query, we do the heavy-chain decomposition for the trie, and then we query the segment tree sum.

Total time complexity is $$$\mathrm O(n\log^2n)$$$.

My code : https://codeforces.me/contest/1207/submission/59299826

This method use so much memory that it will get MLE on test 21 (https://codeforces.me/contest/1207/submission/59296517), but you can get AC by replacing the array with std::map.

Sorry for my poor English.

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

The editorial solution for C,

else {
   d[pos + 1][1] = minOf(d[pos + 1][1], d[pos][1] + a + 2 * b)
}

should it be

else {
   d[pos + 1][1] = minOf(d[pos + 1][1], d[pos][1] + a + 2 * b);
   d[pos + 1][1] = minOf(d[pos + 1][1], d[pos][0] + 2 *(a + b));
}

why the solution ignores the 0 to 1 transition when the s[i] == '1'?

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

I am getting wrong Answer on Test 13 in Problem 1207C Gas Pipeline. My logic is that i am using dp[j][0] which is the cost to bring pipeline to height 1 at position j and dp[j][1] for cost to bring pipeline to height 2 at j. if Character at j is 1 dp[j][0] is -1 which means that it is impossible to bring pipeline to height 1. I am using MAX_VALUE in place of -1 in dp[j-1][0] if dp[j-1][0] is -1 which means it has a very high cost to build the pipeline from there.

Link to my Solution..

https://codeforces.me/contest/1207/submission/59357734

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

Can someone tell me why my submission is giving WA for question D. Thanks in advance

https://codeforces.me/contest/1207/submission/59385418

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

F is not worth 2100.

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

Could anyone give me a greedy solution for problem C. I came up with this approach in the contest but I can't implement it correctly. Thanks in advance!

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

In the editorial of Problem F it states that: "Note that, as in most problems related to sqrt-heuristics, it may be optimal to choose the constant that is not exactly sqrt(N), but something similar to it (but most solutions should pass without tuning the constant)"

Could anyone please explain why it may not be optimal to choose exactly sqrt(N)?

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

    The two parts of the algorithm have O(K) and O(N/K) complexities but the constant factor will not necessarily be the same (e.g. we do a modulo and use more memory for the small x part and always update K elements, while the naive algorithm for large x just sums N/x values which is only at most N/K... many things to consider).

    Pushing K on one side or the other of sqrt(N) will increase the time spent on one part and reduce the other, so because of the constant factors the optimal sum of complexities might be for 0.7sqrt(N) or 3.5sqrt(N) or whatever. Here sqrt(N) is 750 but experimentaly i got the lowest execution time with K around 400.

    Do people really test this in competition though ? Or just guess and round a bit up or down ?

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

[deleted]

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

I've used greedy approach to solve problem C. It fails on test case 13. Please tell me where it goes wrong. Code

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

    You have misread the problem like me:) : the problem says that you MUST start and finish the pipeline on height 1. So you don't need to take the case of the height of the pipeline being 2 for the initial zero subarray, and for the final zero subarray.

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

Please someone explain the problem E !!

I couldn't understand from the editorial.

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

    1) In each query generate numbers in the way to check some bits in any $$$i$$$ case (if we are sure that $$$k_{th}$$$ bit is '1' in choosed number and '0' in answer, then $$$x$$$ has $$$k_{th}$$$ bit also '1', otherwise it is '0' — it follows from the properties of XOR).

    2) Let's fix first $$$a$$$ bits as '1' and choose any combinations in another $$$14 - a$$$ bits. We have to generate $$$100$$$ different combinations, so $$$2^{14 - a}$$$ must be better than $$$100$$$ => $$$14 - a = 7, a = 7$$$ ($$$2^7 = 128 \gt 100$$$).

    So we fix first $$$7$$$ bits as $$$1111111$$$ and increase another, getting the following sequence: $$$11111110000000_2$$$, $$$11111110000001_2$$$, $$$11111110000010_2$$$ and etc.

    3) Using the same algorithm generate another $$$100$$$ numbers, but visa versa: $$$00000001111111_2$$$, $$$00000011111111_2$$$, $$$00000010111111_2$$$ and etc.

    4) From first query answer we check first $$$7$$$ bits using XOR, from another query answer — last $$$7$$$ bits and finally get complete answer.

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

Task F is quite easy to solve and code, but statement is quite hard to understand :D

At first I thought that it is necessary to calculate the sum of all elements $$$a_i = k \cdot x + y$$$, not indexes)

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

In G instead of adding on path to the root and extracting value from vertex we can do: add to a vertex and calculate sum in a subtree (it can be easily verified to be equivalent)

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

Another solution for problem G:

There are no more than $$$S$$$ = $$$2 \times sqrt(4 \times 10^5)$$$ different lengths in the set of all patterns, say $$$L_1, L_2, ..., L_S$$$.

When DFS to some trie node $$$v$$$, among all different patterns with length $$$L_i$$$, there is at most one occurrence ending at node $$$v$$$.
Therefore, maintaining number of occurrences of all different patterns can be done in $$$O(S)$$$ whenever DFS moves to next vertex.

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

Can someone explain how to calculate c12 more elaborately in Div2D?

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

For E

I have an approach but don't know whether it's feasible or not.

Let us denote numbers of $$$1^{st}$$$ query by $$$a_i$$$ and numbers of $$$2^{nd}$$$ query by $$$b_j$$$.So if we select numbers in such a way that xor of any pair ($$$a_i$$$,$$$b_j$$$) is unique. Now let us denote the output to two queries by $$$N$$$ and $$$M$$$ respectively then we can say that $$$N$$$ = $$$a_i \oplus x$$$ and $$$M$$$ = $$$b_j \oplus x$$$.If we now do $$$N \oplus M$$$ then we get $$$a_i \oplus b_j$$$ .Since we selected such numbers that every pair has unique xor we know value of $$$a_i$$$ and $$$b_j$$$ and once we get this we can get $$$x$$$ by $$$N \oplus a_i$$$ or $$$M \oplus b_j$$$.

So my question is there any way to select such numbers that their xor is unique.BledDest

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

Why am I getting runtime error in D? https://codeforces.me/contest/1207/submission/60137631

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

We can also solve E just by brute-force. lets say we gave two sequence (Ai,Bi) to the judge now it will return Ai^x and Bi^x ,take xor of these values we get Ai^Bi. If we can generate two lists of size 100 such Ai^Bi is distinct for every Ai,Bi. This can be done by brute force (have a look at my submission https://codeforces.me/contest/1207/submission/6769403) Now we know the Ai,Bi hence x will be just Ai^(Ai^x).

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

I tried to solve problem C greedily but got WA on test case 13

So please somebody tell me where i am wrong

Solution link : https://codeforces.me/contest/1207/submission/95326809

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

So many of us have got WA on test 13(including me) using the greedy approach for Problem C... Anyone figured out why that is the case? Update : found out myself.