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

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

1366A - Лопаты и мечи

Идея: Roms

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

1366B - Перемешивание

Идея: Roms

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

1366C - Палиндромные пути

Идея: BledDest

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

1366D - Два делителя

Идея: adedalic

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

1366E - Два массива

Идея: Roms

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

1366F - Прогулка по графу

Идея: Neon

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

1366G - Построй строку

Идея: Neon

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

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

I realized in hacking phase that for E I accidentally read in $$$a$$$ and $$$b$$$ both with lengths $$$n$$$ (see my 83457987).

I thought I would segfault in system testing but I was still accepted. Can someone explain from first principles why this is? I guess it's ok to cin out of bounds as long as you don't use the memory afterwards?

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

Hey awoo there is some problem with font of code of f because of comma in mod

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

Can some one please explain me how to do the Linear Integer programming, here in Problem A, they are checking just the corner points of the graph drawn & deciding on the answer,and yes it is quite true when x1,x2 are real numbers, but here the constraint is x1,x2 are integers>=0, so how to approach this problem. please help me with the proof.

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

why it cannot be greater than (a+b)/3 in problem A.

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

Ah, finally the editorial is out now.

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

We can do D in this way too -

1 ) Make prime sieve (sieve of Eratosthenes) to check a no. is prime or not

2 ) Convert given array to set

3 ) Now if a value in set is prime then store (-1,-1) else do brute force to check each valid pair of the divisor.

It passes better than SPF algo (in my case)

Here is link : My_Solution

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

can i get solution for problem D in c++??

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

Объяснение для задачи A просто супер!!!

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

This could be A-hard version :) 478-C Table decorations

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

Hey awoo, I enjoyed the contest, interesting questions! I was wondering why you chose to put F and G in this contest: aren't they better suited for a div 1?

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

Alternative for D, My solution for D is little bit different https://mirror.codeforces.com/contest/1366/submission/83482692 It uses the observation that if (d1 and d2) solution exist for a number A such that gcd(d1+d2,A) =1.Then it will definitely exist in the form of d1 = x, d2 = A/x where x is some divisor of number A.

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

Construction for A: let $$$K = \min(A, B, \frac{A + B}{3})$$$. Each of the $$$K$$$ items crafted needs at least one stick and at least one diamond. Set those sticks and diamonds aside; it's possible since $$$K \leq A$$$ and $$$K \leq B$$$. Each item then needs one additional resource of either type. We have $$$A + B - 2K$$$ resources remaining. It follows from $$$K \leq \frac{A+B}{3}$$$ that $$$A + B - 2K \geq K$$$.

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

Can someone explain the time complexity of Problem D?

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

Can anybody explain a little on why are we traversing the arrays in reverse order helps?

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

Proof for A:

It is evident, as the tutorial mentions, that it cannot be greater than min(A,B,(A+B)/3), as you said. This does not imply that we can always achieve one of these optimal cases! For the first two, it's easy to see that if A>2*B, then it is optimal to pair each B with 2 A's and we have A's to spare. WLOG for B>2*A.

For the other case, we can take 2 of the one with greater quantity and pair it with 1 of lesser quantity. It is easily observed that this will reduce max(A,B) by 1 more than it reduces min(A,B), so we will always be bringing the values A and B closer together, except when they are equal, in that case we create a difference of one. By the above two observations, this process ends either when one of the piles are 0, in which case the other must be 1, or when both piles are 1. This corresponds to cases (A+B)%3=1 and (A+B)%3=2 respectively.

Hence we complete the proof that not only is the optimal less than the 3 constraints, but there exists a way to achieve these 3 constraints.

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

liked the problems a lot, thank u!

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

Please help! In C, why do we check if i <= j?

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

    Let's say the count array is of length 7, odd length
    Now what we equate b/w is:

    • (cnt[0],cnt[6])
    • (cnt[1],cnt[5])
    • (cnt[2],cnt[4])
    • (cnt[3],cnt[3])

    Notice that, equating between cnt[3] and cnt[3] case (i == j) i.e, when both pointers meet at mid is unnecessary and so is, any index > 3 case (i > j) as we will be repeating the process(think).

    Case (i == j) won't happen for even length count array.

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

Can anyone help me find the complexity of my solution https://mirror.codeforces.com/contest/1366/submission/83570373

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

Can anyone explain the proof of how to choose d1 and d2 effectively in Problem D? The editorial version is not that clear to me.

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

    Simple Approach

    For an $$$even$$$ number, answer will be $$$($$$ $$$2$$$, Product of remaining odd prime factors $$$)$$$

    For an $$$odd$$$ number, answer will be $$$($$$ $$$1st$$$ Smallest prime factor, $$$2nd$$$ Smallest Prime factor $$$)$$$

    And obviously, first, you need to check whether alteast $$$2$$$ distinct prime factors for a number exists or not. if not answer will be $$$($$$ $$$-1$$$, $$$-1$$$ $$$)$$$

    Proof

    For an $$$odd$$$ number,

    Consider an example $$$ai$$$ = $$$105$$$ $$$( 3 * 5 * 7 )$$$. Ans is $$$(3, 5)$$$.

    $$$3$$$ is $$$1st$$$ smallest prime factor and $$$5$$$ is $$$2nd$$$ smallest prime factor of $$$105$$$.

    Let $$$x = d1 + d2 = 3 + 5 = 8$$$.

    $$$g = gcd(x, 105)$$$ and obviously $$$g$$$ can't be $$$3$$$ or $$$5$$$. So $$$g$$$ should be greater than $$$5$$$, which is not possible. (why? Let $$$x' = g * e$$$ , $$$e$$$ is even number, $$$e$$$ must be aleast $$$2$$$. You can see $$$x' \gt x$$$ if $$$g \gt 5$$$, which is not possible.So $$$g$$$ has to be $$$1$$$.

    For an $$$even$$$ number,

    Consider an example $$$ai$$$ = $$$210$$$ $$$( 2 * 3 * 5 * 7 )$$$. Ans is $$$(2, 105)$$$.

    $$$105 = 3 * 5 * 7$$$ (Product of remaining odd prime factors).

    You can see $$$d1 = 2$$$ and $$$d2 = 105$$$, now forget about $$$d1$$$ and ask a question from yourself. What is the minimum $$$y$$$, I should add to $$$d2$$$ such that $$$g = gcd(d2 + y, ai) \gt 1$$$. And you will find you need to add smallest prime odd factor, for this case it is $$$3$$$ but we are adding just $$$2$$$ ($$$d1 = 2$$$, hence the answer).

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

For the code for problem G proiveded in the editorial, can anyone please explain why the following transition is skipped:-

dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]), where the ith character of the first string is a '.'.

I am not able to convince myself why this transition is redundant.

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

    Yeah, so the transition look like this:

    1. TAKE character because it will be in *final string

    2. DONT TAKE character because it won't be in *final string, delete it

    3. DONT TAKE character because it won't be in *final string, but we must destroy it with some character '.'

    *final string I am talk about is string t we should get from s after applying function f.

    The transition you are talking about cannot ever happen, because if we took some character with transition 1. , by definition it will be in final string so it shouldn't be destroyed.

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

Anyone please help me to figure out why I am getting TLE on test case 47 , in problem E.Please help me. https://mirror.codeforces.com/contest/1366/submission/83590296

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

Why i am getting TLE for D.

i think it's complexity is same as described in editorial?

https://mirror.codeforces.com/contest/1366/submission/83593262

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

I have a conceptual doubt in problem D.

Let's say our number N has its prime factors p1,p2,p3,p4.

if we choose d1=p1 and d2=p2.p3.p4 ,then IS it NOT possible that x=p1.p3(let) can produce (d1+d2)modx=0 ?

since d1modx!=0 and also d2modx!=0.

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

Problem E is very interesting. Can someone please help me figure out the best possible solution for problem E if condition b[i] < b[i+1] was not in place.

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

Getting wrong answer in the 2nd testcase of C. Can someone please help me find the mistake? Here's the link to my solution: 83472337

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

https://mirror.codeforces.com/contest/1366/submission/83607595

can anyone help me ??what's wrong in my implementation of problem D?

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

What was the intended purpose of lst < prv in the model solution for F? I removed this check and the code is still accepted.

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

Problem A is just bad.