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.

20Input. Program to be unpacked is written to the file PROGR.PAK. This is the filecreated by your packing program.Output. The unpacked program Should be written to the file PROGR.KAP.196. Parallel computations. One of possibilities to make the computations fasteris to execute some of them in parallel; this means that some operations are executed atthe same time. Some of modern microprocessors can execute independent commandsin parallel. The task is to write programs suitable for parallel computations.We will choose a simple model in this problem. Assume that a microprocessor canuse N cells of memory numbered from 1 to N, and it can perform in parallel infinitenumber of commands.Processor can perform these operations:L I J Content of the cell J is saved to the cell having address I.M I JA I JContent of the cell J is saved to the cell having address I. The contentof the cell J remains the same.Content of the cell I is added to content of the cell J, the result issaved to the cell I.S I J Content of the cell I is added to content of the cell J , the result issaved to the cell I.While performing commands in parallel holds the following restriction: At the samemoment it is not allowed to perform two or more commands using the same field. Forexample, it is not allowed to perform in parallel commands M 1 5 and M 2 5. Besides,it is not allowed to change sequence of operations executed with the same cell ofmemory. All commands must be executed. It is not allowed to optimize their.Adjustment of sequence of commands for computing in parallel is done in followingway: commands are grouped into blocks so that operations of commands in thesame block would not intersect (as it is required above). Hence all commands fromthe same block can be performed in parallel.After performing the initial sequence of operations and the same sequence adjusted toparallel computation, the content of memory cells must coincide with each other. If thesame command can be placed to several different blocs, it must be placed in the block withthe least number (assume that blocks are numbered in the order of execution).Task. Write a program to adjust the given sequence of operations for parallel computations,i.e. to group the given commands into blocks.Number of blocks must be the smallest one.Input. The first line of the input file contains the number of memory cells N(1 ≤ N ≤ 1000) and the number of commands K (1 ≤ K ≤ 10000). Commands arenumbered from 1 to K. Remaining K lines contain commands (one command per line).Each command contains one letter (L, M, A or S) and two numbers. If number means thenumber of a memory cell then it is from the interval 1..N, otherwise it can be any integer.

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

Saved successfully!

Ooh no, something went wrong!