1
I’m solving the following OBI problem: https://olimpiada.ic.unicamp.br/pratique/p1/2017/f1/cofre/
Vault Secret The secret system to open this vault is quite complex. Instead of rotating a button several times, as we normally see in the movies, the owner of the safe has to slide a control to the left and to the right, on top of a bar, several times, stopping at certain positions. The bar has N positions and each position contains an integer between 0 and 9 inclusive. In the figure example, the bar has 14 positions and the control is at position 1.
The secret will depend on how many times each of the ten integers between 0 and 9 will appear within the control. For example, suppose the owner slips control from initial position 1 to position 9, then to position 4, then to position 11 and finally to position 13. See that integer 1, for example, will appear six times within the control; and integer 9 will appear four times.
Given the sequence of integers in the bar and the sequence of positions between which the owner slides the control, starting from the initial position 1, your program must count how many times each integer, between 0 and 9, will appear inside the control.
Entree The first line of the entry contains two integers N and M, representing the number of positions in the vault bar and the number of positions in the sequence that the owner will follow to slide the controller. The second line contains integers N between 0 and 9, setting the vault bar. The third line contains M integers representing the sequence of positions that the owner will follow. The first position in this sequence is always 1 and there are no two equal consecutive positions. Exit Your program must print a line containing 10 integers, representing the number of times each integer, between 0 and 9, will appear in the bar control. Restrictions 2 N 105 and 2 M 105 Information on the score In a test set totaling 40 points, N 1000 and M 1000
This is my code: https://github.com/DaviColaresR2-D2/OBI-Problemas/blob/master/Cofre%2Cpy3
N, M = input().split(" ")
N, M = int(N), int(M)
cfo = input().split(" ")
for x in range(N): cfo[x] = int(cfo[x])
cfs = input().split(" ")
for x in range(M): cfs[x] = int(cfs[x])
cfi = []
cfp = []
for x in cfs:
for y in range(x):
cfi.append(cfo[y])
print(cfi)
for x in range(10):
cfp.append(cfi.count(x))
print(cfp)
My problem is to go through the list, for example if something goes to position 5 of the list, and the next has to go to 6, it runs only one position, but my program is running 7 positions (counting with 0), each time it starts again.
How could I fix this?
Please copy the statement and its code to the question, as if one of the links becomes unavailable your question will no longer make sense.
– Woss
Fixed, you could help me now?
– Davi Colares