31.07.2015 Views

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

One instruction can involve 1, 2 or 3 fields of memory. All possible instructionscan be found in the table below. I and J are integers. If I or J means a memory address,then I or J belongs to interval 0..N–1, otherwise – to interval 0..2 k – 1. Dash in the cellmeans that the instruction involves less than three fields. The number recorded in thefield with an address X, we will mark L[X].Instructions are executed subsequently, one after another. If after executing 11, 12or 13 instruction it is moved to another field of memory, the instruction in the newfield is executed and then instructions which follow the last instruction in the newfield are executed (i.e. it is not returned to the previous position in memory).Task. Write an algorithm to execute program for the described machine. Assumethat during the execution of the program neither intermediate nor final data will notexceed the given limits and the program will not be cyclic.Input data are written in two input files. In the first line of the file INT.DAT thereare written two integers N (1≤ N ≤ 8000) and k (0 < k < 60).In the first line of the file PROG.EXC there are written the value of register R(program code starting address) and an integer M (1 ≤ M ≤ N). In the remaining Mlines there are written M numbers: valuesof memory fields from 0 to M –1.Number M indicates how manyfirst fields of memory occupy the programand the data (known in advance)for this program. In the remainingfields of memory there should be writtenzeros and those fields might beused during program execution.Note that during execution of thegiven program for described machine,you may need to enter from keyboardand print to screen.Explanation of the exampleThe memory will look like this:ExampleInputTextINT.DAT PROG.EXC printed to screen10 4 0 102761370012146Address 0 1 2 3 4 5 6 7 8 9Content 2 7 6 13 7 0 0 1 2 14Program is written starting with field 0 (i.e. field having address 0). The firstinstruction will change the content of the 7th field. There will be written 7. Then 13’thinstruction will be executed and it will be moved to the instruction in the 7’th field.There is a printing instruction in this field and after executing it, number 6 will beprinted to the screen. After that instruction in the 9th field is executed. It is a haltinstruction: program execution is over.Note. In a quarter of tests value of k will not exceed 15.17

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

Saved successfully!

Ooh no, something went wrong!