wakanda-forever's blog

By wakanda-forever, 7 months ago, In English

Hello, Codeforces!

I am very excited to invite you to our contest Codeforces Round 1059 (Div. 3), which starts on 17.10.2025 17:35 (Московское время). You will be given $$$2$$$ hours and $$$15$$$ minutes to solve $$$8$$$ problems.

The problems were authored and prepared by wakanda-forever, wuhudsm, tridipta2806 and frostcat.

Note that at least one of the problems will be interactive. So if you are unfamiliar with them, please read the guide for interactive problems before the contest.

The round will be hosted by the rules of educational rounds (extended ICPC). Thus, all solutions will be judged on preliminary tests during the round, and after the round, there will be a 12-hour phase of open hacks. After the open hack phase, all accepted solutions will be rejudged on successful hacks. Also, note that there is no score distribution — rank will be determined by the number of problems solved, followed by penalty; wrong submissions will incur the usual penalty of 10 minutes, following the rules of educational rounds.

Remember that only the trusted participants of the third division will be included in the official standings table. As it is written by the link, this is a compulsory measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:

  • take part in at least five rated rounds (and solve at least one problem in each of them)
  • do not have a point of 1900 or higher in the rating.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

We would like to thank:

I wish you the best of luck, and I hope you enjoy the problems!

UPD: Editorial

  • Vote: I like it
  • +157
  • Vote: I do not like it

»
7 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

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

»
7 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

As an author, I hope you'll enjoy the problems!

»
7 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

Best of luck to everyone — hoping you all see a nice rating increase !

»
7 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

Problems are really cool… would suggest everyone to give this contest and hope you enjoy it…

»
7 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Participate or you will miss some truly beautiful problems.

»
7 months ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

As a tester, I can confirm this problem set is "beautiful".

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I'm really happy to see frostcat as a problem setter. I hope we will enjoy this contest & get +ve delta

»
7 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

As a tester, I was forced to write an as a tester comment

»
7 months ago, hide # |
 
Vote: I like it +13 Vote: I do not like it

As a tester, -. . ...- . .-. / --. — -. -. .- / --. .. ...- . / -.-- — ..- / ..- .--.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a tester, the problems seemed really nice to me, except one.

which was ultra nice xD.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a tester, I can confidently say that this problem set is beautifully designed — it’s genuinely fun and a joy to attempt.

»
7 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

As a tester, regarding questions I would say only one thing, think DP but apply greedy, or maybe vice versa, hope everyone has fun solving problem, all the best :)

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Excited to participate and get some positive delta

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hey all these days I dont understand what is specific color testing and what they do in general ?

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a tester, I can confirm you’re gonna have a great time giving this contest. Don’t miss it!

»
7 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

As a tester, I made a video of solving all the problems. I'll put the stream very soon on Codeforces, don't miss it.

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

A contest with Interactive Problems , its going to be GREAT again

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

18o3 the tester OTZ

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a tester, the problems are really cool and fun to attempt. I hope you all have a beautiful increase in rating.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Good luck everyone! Hope your rating will increase

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

what about the recent decrease?(rollback)

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I was pupil for almost 2 weeks and they suddenly thought of rating rolled back and I got stuck at 1199.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

All the best everyone! Hope everyone gets +ve delta.

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

huge thanks to the authors and testers for their hard work!!!! To all participant, hope your rating will increase

»
7 months ago, hide # |
Rev. 3  
Vote: I like it -6 Vote: I do not like it

Best Luck for everyone in Div.3!!! :)

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I hope there will be an interesting problems!

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a participant , seems interesting.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

WAZAAAAA

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a participant, best of luck, everyone.

And hope this round will be beautiful for everyone!

»
7 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

Is cry's basement already full?

»
7 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

As a participant, SHAW!

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

cout << "Best of luck CODERS for this round!" << endl;

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Be Ready for one INTERACTIVE Problem. there will be one.

Here is guide for Interactive Problems.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

According to the poor situation of QueueForces's submission now, will it be rated?

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can I be a tester for a contest when I reach expert?

»
7 months ago, hide # |
 
Vote: I like it -16 Vote: I do not like it

As a tester,I want to ask:is it rated?(doge

»
7 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

really excited to give an unrated round after a pathetic performance in last round.

»
7 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

hope to reach lgm this contest

»
7 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

div.3 ❌ div.2 ✅

»
7 months ago, hide # |
Rev. 2  
Vote: I like it -12 Vote: I do not like it

I'm sorry about my words.In fact,I think it's an interesting round.

Also,I hope the cheaters will be banned.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

All — Beautiful

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i only got A :(

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This round is Beautiful

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How beautiful the problem are !

»
7 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

ConstructiveForces

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how to H?

»
7 months ago, hide # |
Rev. 2  
Vote: I like it +29 Vote: I do not like it

Oh my god. Please ban all unrated participants, I almost shocked when I see the common standings.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Multiple valid answers everywhere

»
7 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Please ban the Unrated cheaters

»
7 months ago, hide # |
Rev. 2  
Vote: I like it +1 Vote: I do not like it

the interactive snuffed me out, i hate those questions

»
7 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

(Bruteforces + Constructiveforces + Interactiveforces) Typeshit ?

»
7 months ago, hide # |
 
Vote: I like it -7 Vote: I do not like it

constructive forces

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

D was such a beautiful problem. Thank you for the contest <3.

»
7 months ago, hide # |
 
Vote: I like it +25 Vote: I do not like it

No way G went from 200 to 700 in like 5 minutes. Regardless a good contest.

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Is problem D not just binary searching over smallest L and largest R, where the condition is checking if query "1 mid mid" yields a different value from query "2 mid mid"?

  • »
    »
    7 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +1 Vote: I do not like it

    You will exceed 40 if you do binary search for both, it can be done using a single binary search to find L, and the R can be calculated using something else

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    see first find the length of the updated subarray, this can be done by doing 1st operation on 1..n let it be A and 2nd operation on 1..n, let it be B, now r-l+1= B-A. now do BS to find r. now we know r-l+1 value, substitute r their to find l, we cannot do BS on both r and l since it would exceed 40 operations.

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      You're right! I can just binary search over smallest L, then R = L + num_changed, where num_changed is returned from the query "2 1 n"n*(n+1)/2.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    If you can get smallest L, then you can get largest R easily..

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Was E that easy? Please give some hints.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Id like some hints as well, got stuck in it for a long time. Tried some stuff but got WA on 2

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    make cases when there is 1 missing element in the array..when there is 2 missing elements in the array etc.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yes what i did was if vector a has all the values from 1 to n, then just cout a[1] to a[k], else find the missing value. first cout that missing value, next cout a value not equal to missing value and a[n], then rest cout 1 to n excluding missing value and a[n]

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I used the idea of choosing elements which are most apart from each other.

»
7 months ago, hide # |
 
Vote: I like it +27 Vote: I do not like it

lol what is this standing?

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I only AC A and B, I used about half an hour to C. I don't know what I wrong...

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Why did no sample case for B have a solution with a subsequence rather than a subarray?

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Beautiful Permutation — Can someone help me in finding the issue with this code. I'm using binary search to find L and R.

my solution
  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You dont need binary search for R. once you know L then the R will be L + (modified sum of [1, n]) — n*(n+1)/2 — 1

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    just do binary search for L and find the length of the subarray by subtracting sum of original array from the sum of edited array (say d) right pointer will be equal to L+(d-1)

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    see first find the length of the updated subarray, this can be done by doing 1st operation on 1..n let it be A and 2nd operation on 1..n, let it be B, now r-l+1= B-A. now do BS to find r. now we know r-l+1 value, substitute r their to find l, we cannot do BS on both r and l since it would exceed 40 operations.

  • »
    »
    7 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    This will take more than 40 queries , log2(2e4) is roughly 15 (14.28)

    So in your case 4* 15 > 40

    Instead find length using 2 queries by asking whole range sums from 1..n and subtract to get length

    and r = l + (len-1) . L you can find using bs.

    2*15 < 40

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    doing binary search on both l and r will amount to total approx 60 queries. You need to do on only of them then using r-l+1=k u can find the other one.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

bro, i was just lost in life after failing C for like the 10th time, and then i read "u gotta use the current a not initial" pmo

»
7 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

So many bots! How will CF handle this? Will this game still be rated?

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

problem in 2 problem ,this contest should be unrated now

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Really great problems. Enjoyed!

»
7 months ago, hide # |
Rev. 3  
Vote: I like it +35 Vote: I do not like it

Open the status page, and set the filters as follows: Problem G, Verdict Accepted, Language Python3. Look at the submissions that were made just before the contest ended. All of them (literally ALL) are unrated (black) people, and the running time and consumed memory of those submissions are mostly uniform. I looked at some submissions and they looked all AI-generated. They are almost all cheaters.

Coordinators and admins, please look into them.

UPD: I've found that other problems are in the similar situation; generally Python 3 submissions are filled with cheaters.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    Really sad to see my favorite platform getting ruined by cheaters.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    theoretically shouldn't happen because set contains 1 and cover all sums 0..sum_rest, but if it does, skip this c and continue search I have never seen this type of comment being shared tbh

»
7 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

Hello, Constructiveforces!

»
7 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

CHEATFORCES Today,left after solving 4 problems at a ~3.5k rank came back and saw my rank to be 4.9k changed within last 12 minutes of the contest wow , so so many cheaters so annoying dont know how to keep myself motivated having these things

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

This is my code for problem C:

// this is code


#include <bits/stdc++.h>
using namespace std;

int t, n;
int a,b;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    for(int q=0;q<t;++q){
        cin>>a>>b;
        if(b==0){
            cout<<1<<"\n"<<"0\n";
            continue;
        }
        if(a<b) {
            cout<<"-1\n";
            continue;
        }
        if(a==b){
            cout<<"0\n";
            continue;
        }
        int kq=a^b;
        if(kq<=a) cout<<1<<"\n"<<kq<<"\n";
        else{
            int k1=kq^a;
            int k2=k1^b;
            cout<<2<<"\n"<<b<<" "<<a<<"\n";
        }
    }
    return 0;
}

I need an explaination why it is wrong:(((( Anybody please help me:((((

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Your code fails on the following testcase :
    1
    6 7

    Your code gives output as -1 whereas one of the correct output is
    2
    1 0

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    a<b doesn't mean its not possible,400 and 405 is counter case.-1 is answer when number of bits to represent a is less than b

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    a<b => -1 is not a valid statement. For example a=10 and b=15, we can transform a to b as the MSB of b is less than equal to a.

    a=1010 -> 4 from left b=1111 -> 4 from left.

    Correct statement is if MSB of b is greater than a. For example b=17 and a=15 a=01111 -> 4 from left b=10001 -> 5 from left

    Here, you can never toggle the 5th bit in a and hence can never get b.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

cheatforces

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

website got down like 5+ times during contest i dont know for indians or what

»
7 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Beautiful contest, we should have more mainly constructive contests!

»
7 months ago, hide # |
 
Vote: I like it +13 Vote: I do not like it

344346152 344346149 344344898 344348892 344348159 344348061

What a coincidence that they have the same code and the same comments

»
7 months ago, hide # |
Rev. 2  
Vote: I like it +3 Vote: I do not like it

how to prove that we always have a solution for problem G except when n=2?

is it related to pigeonhole principle?

»
7 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

Video Solution of A,B,C,D,E with C++ code of Codeforces Round 1059 (Div. 3): https://youtu.be/ty5y1geayPI

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

In problem B during contest read description several times and stuck with why it says non decreasing subsequence — because literally one of examples used 010 and doubted definition of non decreasing. Now I submit solution, gets accepted, then they say "OOPS actually our example also wrong" and got hacked...

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I was doing hacking and got the following message

Recently, your account was used to crawl. Please change your password to prevent your account from being used for unauthorized activities.

what can i do to avoid it??

Cause till now i have made only 26 hacks (15 successful)

on the other hand i have seen people make 300+ hacks , is there any trick

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You are right. Also i was doing hack. And same action happened.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    And there is a good test case to problem B which given tle for some bitmask or python solutions.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I also got that warning. It disappeared for I while but it reappeared after sending other hacks. A lot of people bruteforced B with bitmasks or python itertools so doing a lot of hacks was easy. Also I can not see any submissions, it shows "page is temporarily blocked by administrator", should I be worried about this?? :(

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Host more div 3 contests

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is this an intentionally bad submission meant to be hacked later? https://mirror.codeforces.com/contest/2162/submission/344344340

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to solve question E if it asked minimum sum of palindrome subsequences instead of palindrome subarrays?

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Just look at the rank list from 150 to 400, a very high density of black people. Submission pattern so random. I think someone made bot to submit with so many account or maybe a very mass cheating group.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

This is rated or not

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

it's not beautiful enough

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

First of all i appreciate the time and efforts made to make this contest, this was very good contest. I am no one to argue for this small mistake. But i want to share something that i face.

In question B, which is now changed, took me more time only because of this test case explanation, i could have accepted this in under 2 min, but took me total 20 min with 2 WA, :(

In the fourth test case, we remove p=010 (indices 3, 4, 6), resulting in x=110011, which is a palindrome. which should be In the fourth test case, we remove p=01 (indices 3, 4), resulting in x=110011, which is a palindrome.

it took me so much time , because i thought above is written non dec , so how could 010 is removed, i was so frustrated.

»
7 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

the standing looks so strange. so many unrated participants with high score.

»
7 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

so cool that hundreds of xxxxxxx people had a stroke of genius​ in a few minutes and completed A-G, and their solutions are exactly the same. in early time you can find that every page of top ranks are full of these fk guys

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Any idea why this logic is wrong for E?

Submission

In a nutshell, I am appending an element that is different from last two distinct elements.

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    then for it , 1123 , now you add 1 ?? (why not add the element which was used quite early and just maintain doing it over all k suffixes ??)

    • »
      »
      »
      7 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      We can do that, but I want to know what is wrong with my solution?

      And from implementation and time complexity perspective both solution are similar

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    i tried a similar approach which was making sure that each addition neither created a length 2 nor a length 3 palindrome, but for example if k = 1 and you have arr = [321112]

    picking an element different than the last 2 elements (1 and 2) can cause you to pick 3 which would create an extra length 7 palindrome (a better answer is either 4,5, or 6).

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I ran into this same idea. Imagine you have [1,2,3,2] for n=4. 1 adds a palindrome, and 4 doesn’t. My solution was to brute force the first 3 elements to find the least amount of palindromes, then repeat that permutation for the rest.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

WHEN WILL THE RATING BE ADDED FOR THIS ROUND?

»
7 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

As a Contestant, I still don't understand interactive problems. But very nice questions.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

huge thanks to the authors and testers for their hard work!!!! To all participant, hope your rating will increase

»
7 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

thanks for the contest!!!

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

thank you

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why does a Interactive problem gives WA instead of TLE when number of queries are exhausted. I feel sad

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I hate constructive

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is Codeforces planning a roll back due to such obvious and impactful cheating?

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I was trying to solve problem E. My approach is 1) If there are >= 3 unique numbers in the array, I will take 3 unique numbers from the tail of the array and append them repeatedly until k turns zero. 2) If the number of unique numbers is 2, then we can introduce a new number (n >= 3, so we have the opportunity) and repeat the previous step. 3) If the number of unique numbers is 1, then we can introduce two new numbers and repeat process 1.

Here is my code,

#include<bits/stdc++.h>
using namespace std;

void helper(int& k, vector<int>& dq, vector<int>& ans) {
	while(k--) {
		int value = dq[0];
		ans.push_back(value);
		dq[0] = dq[1];
		dq[1] = dq[2];
		dq[2] = value;
	}
}

void solve() {
	int n, k; cin >> n >> k;
	vector<int> a(n), ans;
	set<int> s;
	stack<int> st;
	for(int i = 0; i < n; i++) {
		cin >> a[i]; s.insert(a[i]);
	}
	for(int i = 1; i <= n; i++) {
		if(s.find(i) == s.end()) st.push(i);
	}

	vector<int> dq;
	dq.push_back(a[n - 1]);
	for(int i = n - 2; i >= 0; i--) {
		while(i >= 0 && dq.back() == a[i]) i--;
		if(i >= 0) dq.push_back(a[i]);
		else break;
		
		while(i >= 0 && (dq[0] == a[i] || dq[1] == a[i])) i--;
		if(i >= 0) dq.push_back(a[i]);
		else break;
		if(dq.size() == 3) break;
	}
	reverse(dq.begin(), dq.end());

	if(dq.size() == 3) {
		helper(k, dq, ans);
	} else if(dq.size() == 2) {
		dq.push_back(st.top());
		ans.push_back(st.top()); st.pop(); k--;
		if(k > 0) helper(k, dq, ans);
	} else {
		if(k > 0) {
			dq.push_back(st.top());
			ans.push_back(st.top()); st.pop(); k--;
		}
		if(k > 0) {
			dq.push_back(st.top());
			ans.push_back(st.top()); st.pop(); k--;
		}
		if(k > 0) helper(k, dq, ans);
	}
	for(int i = 0; i < ans.size(); i++) cout << ans[i] << " "; cout << "\n";
}

int main() {
	int t; cin >> t;
	while(t--) solve();
	return 0;
}

I got WA repeatedly at testcase no 2. Can someone give me some good test cases? Thanks in advance.

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

round was amazing

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

problems are cool

but difficult for me

(Because I'm newbie)

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I dont get it why my solution does not work, WA on testcase 2/53, can somebody have a look? Thanks

345461995

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Ready for the Contest!!

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello, My submission for problem 2162B was flagged for coinciding with another user’s solution. I would like to clarify that I wrote the entire code myself during the contest and did not share it with anyone or post it publicly. It is possible that someone else might have accessed my solution or replicated a similar approach. I understand the importance of maintaining fair competition and assure you that this was unintentional. Kindly review my case. Thank you for your understanding

»
7 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

I believe my solution #344352270 for problem 2162B was flagged because I accidentally used Ideone in public mode. I didnt realize that my code could be viewed by others, which is likely how someone copied it. I had no intention of sharing or violating the rules, and I sincerely apologize for the mistake. I’ll make sure to use private settings in the future ;(

»
7 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for E secondtestcase's 3rd case 1 1 3 is producing 2 2 1 while my code is producing 2 1 3 for 113221 number of palindromic subarrays are 8 but for 113213 they are 7 so what am i doing wrong i aint know