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

Автор mohammedehab2002, 7 лет назад, По-английски

Hi!

I'm back with not one, not two, but three contests, although I have no promises about when to expect them....

The first of them, codeforces round #563, will take place on Jun/03/2019 17:05 (Moscow time). It's rated for the second division, but, as usual, first division participants can take part out of competition.

I'm the problemsetter of the round. I'd like to thank KAN for coordinating the round (and his patience .. try coordinating ~20 problems), arsijo for helping with the preparation, Um_nik, _overrated_, Aleks5d, wiwitrifai, pllk, Bedge, Ivan19981305, and PrianishnikovaRina for testing the round, and MikeMirzayanov for the great codeforces and polygon platforms.

In this round, you'll be given 6 problems and 2 hours to solve them.

UPD: I decided to drop the 3 seconds rule. The scoring distribution is 500-1000-1500-1750-2500-2500. That means you should probably read both E and F :D

Good luck & Have fun!

UPD: here's the editorial.

UPD: congratulations to the winners!

Div.1+Div.2:-

  1. tribute_to_Ukraine_2022
  2. E869120
  3. 800iq
  4. cerberus97
  5. Anadi

Div.2:-

  1. 800iq
  2. Alex18mai
  3. Mikaeel
  4. prick
  5. wasyl

See you in the second round :D

  • Проголосовать: нравится
  • +466
  • Проголосовать: не нравится

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

Trying to make enough money to afford MIT. I see you. Only a few ten thousand dollars left np

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

By tradition, the scoring distribution will be announced 3 seconds before the contest.

So accurate!

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

Imagine next rounds you would actually use high precision clocks to measure the interval of announcing score distributions... ;)

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

The time is good for Chinese.

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

i m very excited about the new contest

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

4 contests in the next 7 days, great.

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

Looking forward to more fun XOR questions

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

Upvoted for creating 3 contests simultaneously (Great job!).

Downvoted for not capitalize "Codeforces" and "Polygon".

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

It seems that another competition season has come

So many contests these days :)

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

mohammedehab2002 previous rounds all problem names start with "Mahmoud"(round #396), "Ehab"(round #525) and "Mahmoud and Ehab"(round #473). Guess which start is next ??

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

up to which rating second division?

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

Wait, sorry guys I am new here. Do you have to start at that exact time? Or is there a contest window where we can choose to do it?

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

Let's get ready to rumblllllllleeeeeeeeeeeeeeeeeeee!!!!!!!!!!!!!!

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

Hope this round not unrated and no accident

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

Do we have a hacking phase?

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

Scoring distribution shall be announced 3 seconds before contest

I decided to drop the 3 seconds rule. The scoring distribution is 500-1000-1500-1750-2500-2500.

Rules are made to be broken here. xD

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

You really like GCD and prime numbers ! (WOW!)

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

Apparently, it wasn't.

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

How To solve problem D ?

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

    Think in terms of prefix xors.

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

    Instead of directly construct the array, just construct the prefix xor version of the array S1, S2,..., Sn. So the condition that no subseg has the xor equals to 0 or x is the same as the array S is distinct and there is no pair in S that xor of them is x.

    So iterate from 1 -> 2^n-1, if x^i also belongs to the given range [1, 2^n) then just pick one, or else pick both.

    To construct the answer array A from S, use : Ai = Si^S(i-1).

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

    First observation, if there is no number x restricted. You can simply construct something like 1 2 1 4 1 2 1 8 1 2 1 4 1 2 1... This pattern is optimal because at every i-th number where i is 2^x, you cannot add any new number using numbers in range [1..2^x), any new addition will cause XOR to be 0. Hence, you will need to add 2^x every time you are at the 2^x-th number (1, 2, 4, 8, 16, ...).

    Now, what about the restricted number? Well you can simply take the biggest 2^x that forms x. e.g. if x is 5, restricted number will be 4. Now, you can simply skip the restricted number when you want to form the sequence. (Why biggest? To minimize the largest number in the sequence) e.g. x = 5 1 2 1 8 1 2 1 16 1 2 1 8 1 2 1, if at any time the number has exceed 2^n, just stop adding new sequences.

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

    What can be pretest 7?

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

    I will explain the complete solution of D.

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

I found B to be harder than C and D maybe because I was approaching it wrong way.

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

How to solve B? And why does it get TLE 55041556 ?

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

Hints for F please.

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

I've seen successful hacks made. Any hints what they were about?

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

How to solve F?

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

god damn it when I started to feel I'm halavin I failed on the fourth hack

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

Hints for F? Can it be solved using LCA?

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

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

How to think and approach problem D?

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

    Every number has only one number that makes (A^B == X) true. The problem asks for sub segment so it's another way to tell you to think of prefix xor. The answer should be clear after that.

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

fml, my bug on F was that I'm doing return the answer if there is only one edge from the current node, which should be the back edge to the parent, but I forgot the root!

Nice round, I really liked it :D

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

Any ideas for E? i see most solution use dp. can anyone explain!

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

    For E, $$$a_1=p_1^{e_1}p_2^{e_2}$$$. then max is $$$1+e_1+e_2$$$. that's exp step down. so $$$a_1$$$ must be $$$2^k$$$ or $$$2^{k-1}3$$$ (if $$$\leq n$$$). then remain is combination count. but no time to code.. the annoying $$$3$$$.

    Am I right? or is there a better solution? wait for tomorrow morning:) sleep now

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

    Actually, I didn't use DP. I used only multiplying. Seriously, I didn't use DP.
    My solution of problem E is as follows:

    ---

    Step 1: What is the maximal possible value of $$$f(p)$$$?
    Actually, the maximal possible value of $$$f(p)$$$ is as follows:

    • $$$1 \leq N \leq 1$$$ : $$$max=1$$$
    • $$$2 \leq N \leq 3$$$ : $$$max=2$$$
    • $$$4 \leq N \leq 7$$$ : $$$max=3$$$
    • $$$8 \leq N \leq 15$$$ : $$$max=4$$$
    • $$$16 \leq N \leq 31$$$ : $$$max=5$$$

    But why? Think about the sequence of {$$$g_1,g_2,g_3,...,g_k$$$} if you assume $$$g_1 \gt g_2 \gt g_3 \gt ... \gt g_n$$$. For example, if $$$A=$$$ {$$$4,6,2,1,5,3$$$}, the prefix gcd will be {$$$4,2,2,1,1,1$$$}, so $$$g$$$ will be {$$$4,2,1$$$}.

    Because the optimal sequence of $$$g$$$ is {$$$2^{k−1},2^{k−2},2^{k−3},...,4,2,1$$$}. Suppose $$$N=11$$$. For the sequence {$$$8,4,2,1,11,10,9,7,6,5,3$$$}, it is easy to find that $$$g$$$ is {$$$8,4,2,1$$$}.

    ---

    Step 2: How many ways are the maximal answer?
    Let's think about writing the value of $$$a_i$$$ which changed the prefix gcd. For example, if $$$g$$$ is {$$$8,4,6,5,2,3,1,7$$$}, the values that you will write will be {$$$8, 4, 6, 5$$$}.

    So what is the possible sequence of values which you will write? Suppose $$$N=8$$$.
    • 1st value: $$$8$$$. Only $$$1$$$ way.
    • 2nd value: $$$4$$$. Only $$$1$$$ way.
    • 3rd value: $$$2, 6$$$. $$$2$$$ ways are possible.
    • 4th value: $$$1, 3, 5, 7$$$. $$$4$$$ ways are possible.

    So the number of possible sequence of values which you will write will be $$$1 \times 1 \times 2 \times 4 = 8$$$.
    But, how about the other values? If sequence is {$$$8,4,6,5$$$}, you should insert other values: {$$$1,3,7,2$$$}.

    You should think about inserting in order of $$$1, 3, 7, 2$$$. (Insert from values which is not divisible of $$$2$$$, next not divisible for $$$4$$$, next not divisible for $$$8, 16, ...$$$

    • There are $$$1$$$ ways to insert $$$1$$$: Just after $$$5$$$.
    • There are $$$2$$$ ways to insert $$$3$$$: Just after $$$5$$$, or just after $$$1$$$.
    • There are $$$3$$$ ways to insert $$$7$$$: Just after $$$5$$$, just after $$$1$$$, or just after $$$3$$$.
    • There are $$$5$$$ ways to insert $$$2$$$: Just after $$$6, 5, 1, 3$$$, or $$$7$$$.
    So for each sequence you wrote, there are $$$1 \times 2 \times 3 \times 5 = 30$$$ ways of insertion. It means there are $$$8 \times 30 = 240$$$ permutations of $$$N=8$$$ which is maximal.

    So, let's move on another example. Suppose $$$N=11$$$:
    • Ways to write: $$$1 \times 1 \times 3 \times 6 = 18$$$ ways
    • Ways to insert the other values: $$$1 \times 2 \times 3 \times 4 \times 5 \times 7 \times 8 = 6720$$$ ways
    • So, the answer will be $$$18 \times 6720 = 120960$$$.

    Did you get it? :)

    ---

    Step 3: Thinking about other cases, not only $$$g =$$$ {$$$2^{k−1},2^{k−2},...,4,2,1$$$}
    If $$$N=12$$$, not only {$$$8,4,2,1$$$} is maximal, but also {$$$12,4,2,1$$$}, {$$$12,6,2,1$$$}, {$$$12,6,3,1$$$} is maximal.
    So you should brute force sequence $$$g$$$ (There are up to $$$O(\log N)$$$ ways). If you determined the sequence $$$g$$$, you can do like step 2: first calculate the number of sequence that you will write, second calculate the number of ways of insertions and finally mutiplies.

    Since the complexity for each $$$g$$$ is $$$O(N)$$$, so the total complexity is $$$O(N \log N)$$$. If you precount factorial and inversions, you can also solve with $$$O(N+\log^2 N)$$$.

    Sorry for my poor English.

    Code (Uploaded at 2:01 JST, 56 minutes after the contest)
»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

seems that problem B shares the same trick with problem C in Global Round 3..

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

I like problem E.

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

Thanks for mathforces (no)

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

61741833-1039620329569556-2416932415634145280-n

X is 29.

Apparently this tc was not there in PreTest of F.

Naive Solns asking only type 2 queries will take atleast 8 queries.

Extending this tc — for $$$n*(n+1)/2$$$ vertices will take $$$n$$$ queries.

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

In the problem A, it was mentioned in the problem that order of the array should not be changed! What did that line mean and how do we reorder it without changing the order? Please Help!

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

$$$A, B$$$ and $$$C$$$ felt like typing test. The situation drastically changed afterward :(

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

Very very nice contest, 10/10. Tl63 just because of using included sort. I hate this test -_-. But in general all it was good.

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

Can someone explain how to solve this example in F?

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

wow I got TLE on test 63 and my rating is gone

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

    The test 63 is the hack I used during the round, so I want to clarify a couple of points:

    First that seems the only test with anti Quick sort test, I can see that 150+ solutions failed this test and if it wasn't added all these solution may have been passed, I've also always see Quick sort solution pass sys test in previous rounds, so I think such test should be always added to any problem that require sorting.

    Also I'm not very proud with that kind of hack, because all I did is check if a java solution that uses sort for primitive array, so I want to raise attention against this.

    For those who still want to use primitives you can build your own sort function like the radixSort function that I use in my solutions, wich I copied from uwi code ( I hope he doesn't mind )

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

JAVA submissions have been judged on the C++ time limit for the B question. Getting a TLE for an O(nlogn) approach. However I didn't use a StringBuilder which is bad on my part but still a correct solution should pass.

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

Hope that the rankings would be revised. Otherwise rating would take a great hit.

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

55036867 why using StringBuildfer was wrong and a get TLE? java

UPD: 55052153 problem was oin primitive types, only in that, i am so disappointed=(

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

Lmao, I was so pissed when my naive solution for F had bugs and didn't get accepted, while so many people solved it.
Now I see anyway my naive solution would have got verdict Wrong answer on test 99xD.

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

Wrong answer on test 99. Such pain in F

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

Problem F
qkbjv

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

I passed F in last 5 minutes. Exciting!

Thanks for the round very much!

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

Sorry, does the #23 testcase from F shows "wrong answer query limit exceeded"?

I made a submission with assertion but couldn't see that I was exceeding the limit. 55048680

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

https://codeforces.me/problemset/problem/1054/D a question similar to today's D

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

Nice Contest.

Btw a simiar (a̶n̶d̶ ̶a̶n̶ ̶e̶a̶s̶y̶ ̶v̶e̶r̶s̶i̶o̶n̶?̶) of F recently appeared in Codechef Cook Off MYS00T

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

Problem F, a very nice tree and interactive problem! Thanks for writers.

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

Well I'm stupid and haven't debugged my F during contest, but here is my solution that should works but it got AC:

First of all let's know a height of x by first type of query with vertex 1, let it be H.

Let root be the lowest vertex that we know that has X in it's subtree.

So let choose a type of query randomly!

If we chose first type then just choose some vertex with height H in root subtree randomly and then change root!

If we chose second type then just change a root!

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

Was a randomized solution intended to pass for F?

Instead of using any heavy-light/centroid decomposition, I just picked a leaf at random for the current subtree, and then asked similar queries as given in the editorial.

https://codeforces.me/contest/1174/submission/55047296

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

Since editorial is not linked — EDITORIAL

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

^ Click here to go up! ^

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

how. to. calculate. the. contribution. ?why. the. contribution. for. me. is. negative. ? i. do. nothing. God

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

Very neat and clear problem descriptions. Thanks to the writer.

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

I think there is a time limit problem in problem 2 for java. Same logic gets accepted for C++ but TLE for java..

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

How to solve the problem D ??