alyosha's blog

By alyosha, history, 6 months ago, In English

https://mirror.codeforces.com/contest/2154/submission/345771218, this is my solution of the problem. I am not sure why it's failing I am using the exact same idea as in editorial. It's giving TLE due to some implementation error. Can you someone please correct. Any input is welcome. I have tried to comment the code a bit to make the parts of it understandable. Please ask for any clarification if needed. Thanks

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By alyosha, history, 7 months ago, In English

https://mirror.codeforces.com/contest/2149/submission/340722817 this is my submission it is failing by TLE on testcase 15. I don't understand why. I have implemented the same approach as given in the editorial. I compress the values of array A and the do 50 tries of randomly checking if count of some value in [L, R] > (r — l + 1)/3.

Any help will be appreciated. Thanks

Full text and comments »

  • Vote: I like it
  • -2
  • Vote: I do not like it

By alyosha, history, 10 months ago, In English

Hello,

I just finished the Cisco Placement Test for batch 2026(India). It was 40 MCQ + 2 CP problems. Both of the CP problems were tree based, but I wasn't able to solve either of them. Definitely not going to get selected. But would like to discuss the problems and possible solutions.

First Problem: Given a tree with n vertices (Some of the vertices contains coin) and a binary string of length n denoting which vertex contains coins. You can collect a coin if the number of edges from your current vertex to the coin vertex is <= 2. You can start with any vertex, but after collecting all the coins you need to end at vertex you started at. what's the minimum path length you need to collect all the coins n <= 1e5 (length of the path is number of edges in the path).

Second Problem: Given a tree with n vertices. a start_vertex and an end_vertex, with a list of vertex, starting from the start_vertex you need to visit all the vertex in the list of vertex (in any order) and finish at the end_vertex. Find the minimum path that does this.

For the first problem I was really clueless how to solve it maybe there's some DP approach, For the second problem it's possible to solve it with multiple dfs but It felt to complicated to code in the given time.

Is there any elegant or easier way to solve these problems. Any discussion will be helpful.

Full text and comments »

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

By alyosha, history, 11 months ago, In English

Hello, I was solving Salary Queries in CSES. I coded a BIT solution with complexity O(nlog^2(x)) solution but it doesn't pass all the testcases as it takes approx 3.5 seconds to run. Here's the link to the code https://cses.fi/paste/af0c566bad71c1a7c62bff/ . I don't want to use pre-code data-structures as I want to practice implemtation as well. All the solution i found on the internet contains unordered_set already implemented. Any suggestions are welcome.

Thanks

Full text and comments »

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

By alyosha, history, 20 months ago, In English

link to submission: https://mirror.codeforces.com/contest/1790/submission/277762835 link to problem : https://mirror.codeforces.com/contest/1790/problem/G

I have been trying to solve it for few hours now. I am getting wrong answer on test-case 5 sub-test : 1634

My approach is similar to what is given in the editorial. My approach is: first I run a breadth first search to find the nearest vertex with token in it and it's path contain only bonus. I take the dis vector to keep it's distance from 1. Then i want to check if there is a edge whose both endpoint is a bonus vertex. If so then is there an vertex with token in the neighbouring vertex of that edge(excluding the already found nearest to 1). If there is then answer is definitely yes.

Otherwise: for each bonus vertex find the number of token near it. and these would be the number of moves I can make to help reach nearest token to token 1.

I am not sure what I am doing wrong . If you have any advice on how solve it please help. Thanks.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By alyosha, history, 21 month(s) ago, In English

Problem Link : https://cses.fi/problemset/task/1750 Submission Link : https://cses.fi/paste/f2a12df5ba1948a496b5bf/

I am not sure why my code this TLE on one test case (where N and Q are 10^5). I tried doing it using binary Lifting , The matrix A is used to store descendants at 2^j position where j<= 35

I believe the solution should not take more then O(q*35+35*n) steps.

Can someone Please help me out?

Full text and comments »

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