Блог пользователя calculus.saransh

Автор calculus.saransh, 13 лет назад, По-английски

Question A


This was a straight forward question which required the checking of "0000000" or "1111111" as a substring contained in the given string. Java implementation allows the use of str.contains() function which makes the code very short.

Question B

This question could be solved by brute force considering the small constraints for this question. Keeping a recursive method which takes the temporary number created till now the count of fours and sevens and global variable which stores the answer can help us solve the question with ease.

Question C

Again a straight forward implementation. Some of the things to note. If the string contains the substrings all characters of that substring have to be replaced. Hence we replace with the favorite char but if the favorite char is already there we replace with 'A' or 'a' because that happens to be lexographically smallest. Corner case- Favorite char is 'A' , if yes.. if 'A' is present as a part of substring replacement is done by 'B'.

Question D

Some of the things which I did not take note of during the competition which prevented my solution from passing. Use adjacency list instead of matrix as the number of roads are only 1000. The question says that there can be multiple roads between junctions so updation needs to be done to adj[s][e] when a lower distance comes up.

Approach

A combination of djikstra and DFS allows us to find the minimum cost incurred in traversing the points. Update your djikstra cost array at all nodes which can be visited from the taxi you are in. This can be done using DFS. Again find the minimum cost junction and continue. If at the end you are not able to reach the destination output should be -1.
Разбор задач Codeforces Beta Round 77 (Div. 2 Only)
  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится