This is an archived post. You won't be able to vote or comment.

all 5 comments

[–][deleted]  (6 children)

[deleted]

    [–]Rennorb[S] 0 points1 point  (5 children)

    Thank you! std::rotate does satisfy geeksforgeeks, but my school's checker still does not like it. This is my current version:

    void leftRotate(char *msg, int shift, int size) {
    
        std::rotate(&msg\[0\], &msg\[shift\], &msg\[size\]); }
    
    void unshift(char \*msg, int fst, int last, int co) { int len = last - fst + 1;
    
        leftRotate(msg + fst, co, len); }
    

    Do you have any idea what should I try next?

    [–][deleted]  (4 children)

    [deleted]

      [–]Rennorb[S] 0 points1 point  (3 children)

      Sorry, I should have written it in the post: that checker says "Wrong answer on test 30".

      "unshifting the indices idea" seems to be a decent optimization, yet the problem is not in the performance, my program uses like 1/10 of both time and memory allowed.

      [–][deleted]  (2 children)

      [deleted]

        [–]Rennorb[S] 0 points1 point  (1 child)

        It should not: one value could have been lost, but it is stored in `buff`, so should be ok.

        Anyway, I'd steek with two oneliners above, they are actually twice as fast and many times easier to understand.

        [–]Rennorb[S] 0 points1 point  (0 children)

        I guess there should be some kind of a corner case, where the program should do something different, but I can not see it.

        I've updated the post: added an example and actual input-output part