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

Автор koderkushy, история, 6 месяцев назад, По-английски

2158A - Suspension Idea & Solution: kingmessi

Hint 1
Hint 2
Hint 3
Tutorial
Solution
Bonus

2158B - Split Idea & Solution: kingmessi

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Tutorial
Solution

2158C - Annoying Game Idea & Solution: kingmessi

Hint 1
Hint 2
Hint 3
Hint 4
Tutorial
Solution
Bonus

2158D - Palindrome Flipping Idea & Solution: kingmessi and abc864197532

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Tutorial
Solution

2158E - Sink Idea & Solution: kingmessi

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Tutorial
Solution

2158F2 - Distinct GCDs (Hard Version) Idea & Solution: koderkushy

Tutorial
Solution (Python)
Solution (C++)
Разбор задач Codeforces Round 1067 (Div. 2)
  • Проголосовать: нравится
  • +83
  • Проголосовать: не нравится

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

Auto comment: topic has been updated by koderkushy (previous revision, new revision, compare).

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

what an amazing solution for problem D!

Thanks!

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

For problem F2, it may be easier to randomize set X instead of using a formula. It's enough to take the first 21 prime numbers and multiply 11 random ones among them: 351258817

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

For anyone who needs just an add-on to understand the editorial for B a little better

I really got cooked by this problem but finally came up with a solution that happened to match the editorial 2 hrs post contest lol

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

My solution for D is exactly similar to the editorial lol

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

My solution for C didn't pass because of +1 :(

For the last 30 minutes I was writing SEGMENT TREE OF ALL THINGS.

Quite sad, but it's alright because I absolutely LOVED the contest, thanks a lot for the good problems

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

When the question suggests outputting -1 for impossible case, but there isn't any in input example.
Doakes Meme

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

A new node idea in E is quite amazing. Nice problem!

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

Got a new logic for Pb B without using mod 4 stuff. Check my solution here https://mirror.codeforces.com/contest/2158/submission/351225505 (It is not clean though, I was in a hurry to submit XD )

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

In C after the idea of differentiating between $$$k$$$ odd and even you can also just use Kadane's Algorithm: Maximum Subarray Problem.

See here 351210965. With even $$$k$$$ we just use Kadane's algorithm. With odd $$$k$$$ we add another state: The best possible sum, assuming we already used Alices one move to add $$$b_i$$$ to one number.

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

can someone tell the issue in my code

351260725

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

    You are assuming that the answer for the 'odd k' cases will lie in the subarray which includes the subarray found using kadane's algorithm, but this is not necessarily true. Below is one of the cases when this would fail.

    1
    4 5 
    3 -5 2 0
    3 2 4 5
    

    The answer that your solution would give is 6 (includes the 0th index only) while the actual solution is 7 (the subarray from 2nd to 3rd index along with b[3]).

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

-106

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

In Problem F2, I wrote a randomization program and found 100 numbers with pairwise distinct gcd values.

randomization program

The probability of this randomization program succeeding was low, but I was lucky enough to stumble upon one such set of numbers.

After obtaining these 100 numbers, the construction method for this problem is the same as in CF1981D.

The submission

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

Can anyone tell me the problem with my code for D?:

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

Problem D can also solve through bfs .

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

    Solution from editorial looks complicated. Alternate solutions are easier to come up to, though probably a bit harder to implement.
    You already mentioned the BFS, I want to add that brute force is also possible.
    So, we move from left to right, transforming current element of s into t, until 4 elements are left (4 is a guess, coming from fact that n is >= 4 by problem statement).
    It can be done greedily. Say, current element of s is 1 and in t it's 0. Let's find next closest 1 in s. Interval between current element and that next 1 will be palindrome (because there are 1's on sides and all 0's in the middle). If there are no more 1's in s, it means all elements to the right are 0's, so flip them all since they form a palindrome, now we have all 1's, so flip again to get all 0's.
    Thus, in at most 2 * (n — 4) operations we transform first n — 4 elements.
    For the remaining 4 elements use either bruteforce of BFS. There are only 2^4 * 2^4 combinations, so we can just try all of them and make sure that all can be done withing 8 operations.

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

      how did you calculated that " There are only 2^4 * 2^4 combinations ".

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

        There are 2 ^ 4 binary strings with 4 elements, because each element has 2 possible values (0 and 1). We have 2 binary strings containing 4 elements each, thus for each of 2^4 possible values of 1st string, there 2^4 combinations of the second string. Or we can view 2 strings of lenght 4 as a 1 string of length for. Thus we have 2^8, which is equal to 2^4 * 2^4.

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

How does solution for D ensure that we're doing it in minimum operations?

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

Did any one write recursive dp solution to problem C?

Here is a version

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

the question C's solution is wrong because for this test case:

1 3 3 2 -7 3 1 -10 3

alice will not add -10 but subtract it so with your solution the final array is 2 -7 6 ans: 6 but the answer should be 2 3 3 ans: 8 i think you should update it and if can update the solution of this question @kingmessi

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

Is the solution given in the editorial for problem C is correct ??

Because if I have

n=1,k=1 means just 1 move and 1 size array made by Alice only

and if the array is

a={1}, b={-4}

if i am using the editorial solution it is giving me output -3 but it should be 5 naa i think because we can do either a[i]=a[i]-b[i] or a[i]=a[i]+b[i] so whyy can't we do here a[i]-b[i] in editorial it is always doing +b[i]

or i am incorrect thing is some other direction can any one please help and tell me the reason

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

Can anyone please tell me why this solution is not working ?

My Submisson

I have used the same concept similar to editorial 1 kadane's algo logic but is failing i have also added proper comments there can anyone please tell me why it is falling it will be very helpful for me

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

D: Repeat: flip the substring from the first 1 to the next 1.

When there is only one 1 left, it can be zeroed out in at most 3 flips.

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

simpler method to get "11..."

// this is code
vector<pair<ll,ll>> cal(string s){
    vector<pair<ll,ll>> p;
    if(s[0]!=s[1]){
        if(s[1]==s[2]){
            s[1]=s[2]=s[0];
            p.push_back({1,2});
        }
        else{
            if(s[2]==s[3]){
                p.push_back({2,3});
                p.push_back({1,3});
                s[1]=s[2];
            }else{
                p.push_back({1,3});
                s[2]=s[1];
                s[1]=s[3]=s[0];
            }
        }
    }
    for(int i=1;i<s.size();i++){
        if(s[i]!=s[i-1]){
            p.push_back({0,i-1});
        }
    }
    if(s[s.size()-1]=='0')p.push_back({0,s.size()-1});
    return p;
}
»
6 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Why no test cases in D with output = -1 ? Many codes could be hacked !! Like
Input:
1
2
01
10

Output:
-1

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

https://mirror.codeforces.com/contest/2158/submission/351409705 why this fails can anybody give testcase?

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

What an amazing question f2. My blog https://mirror.codeforces.com/blog/entry/148841 contains a proof-style explanation of F2, which may be helpful if you like formal proofs :)

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

What would be the expected rating of D?

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

is the checker in problem D wrong? cause in test 1 even when my code print valid operations, the checker log still is "wrong answer Invalid operation: substring is not a palindrome (test case 1)", could anyone check the code for me? here is my code 351716981

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

like the solution to B

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

Wow!Amazing problemn for D!

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

Solution for D — wow!

»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
Hey everyone I'm looking for a cp peer group, if anyone can let me join in do let me know. Thank you
»
6 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Nowadays B is getting more hard and hard right?

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

Question B is great! I totally get it now.

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

really great editorial

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

Third problem can be more complex if u just add -1e6<=bi<=1e6

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

D was so good. i feel proud of myself that i could come up with the same solution given in the editorial. (though it took me half an hour to think and another half to code :))

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

Could someone please explain why in C we need to do L[i] + R[i] + a[i] + b[i]? Why do we calculate max subarray sums for either sides of i?