31.07.2015 Views

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

station) ts (1 ≤ ts ≤ 150). In each of the further ts lines there is given informationabout one intermediate (or arrival) station: number of town a (1 ≤ a ≤ M), to which itis arrived and the duration of the journey to it from the preceding station in hours h(0 ≤ h ≤ 10000) and minutes min (0 ≤ min ≤ 59).Hence, the description of one route takes ts +1 line.Output the results to the first line of the output file. Write IMPOSSIBLE if it isimpossible to travel across the world, taking the given routes only; otherwise outputthe minimal time needed for the journey across the world: number of days(1day=24hours), hours and minutes.ExampleInput Output Comments5 3 33 5 35 31 2 444 21 75 7 181 8 23 13 16 235 6 23 23 18 122 17 322 0 46 The journey will take 2 days and 46 minutes.The traveler departs from the third town at5:35 and arrives to the first town after 2 hoursand 44 minutes, i.e. at 8:19. The travelerdoesn’t have any transport immediately, so heshould wait until morning and leave to thethird town at 8:23. The journey there takes 16hours and 23 minutes.23199. B. Byte Designs a Word Processor. Programmer B. Byte took example fromhis younger assistant B. Bit and decided to design a more powerful word processorhimself. One of the operations that the word processor should perform is to find aphrase in the given text.B. Byte decided that it would be easier for him if after indicating the fragment, hisword processor could find the places where the phrase was discovered in the text andwould make an appropriate table.Phrases can cover each other. For example, the phrase AMA repeats twice in thetext AMAMA. Upper-case and lower-case must be regarded while searching for phrase.Task. Write an algorithm to find all the places where the phrase is discovered in the text.Input. The first line of the input file contains two integers. These are the number oflines n (1 ≤ n ≤ 250) in the phrase and the number of lines m (1 ≤ m ≤ 25000) in the text.The further n lines contain the phrase and in the remaining m lines text is presented.Text and phrase can contain letters, spaces, numbers, and punctuation marks only.Phrase and text are reduced to lines, 80 symbols per line. The last line of phrase andtext can be shorter. None of the lines end with space.Assume that always the last symbol of any line belongs to the same word as thefirst symbol of the further line, i.e. the end of line never means the end of word.Output the results to the output file. If the given phrase was not encountered in thetext, write zero (0) to the output file. Otherwise in output file there should be such a

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!