eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Processor`s game

Processor`s game

Vasya Pupkin’ coursework on electronics is to create a simple microprocessor. According to the statement this microprocessor has only three registers: the accumulator, the instruction pointer and stack pointer. The accumulator has \textbf{60} bits, the instruction and stack pointers has \textbf{7} bits. The accumulator can store positive and negative numbers (in binary complement code: Binary complement code of negative number is equal to difference between \textbf{260} and absolute value of that negative number. For example, \textbf{-5} in decimal complement code could be written as \textbf{1152921504606846971}, and in binary com-plement code as \textbf{111111111111111111111111111111111111111111111111111111111011}). The processor can execute the following commands (\textbf{ACC} -- the accumulator, \textbf{IP} -- instruction pointer, \textbf{SP} -- stack pointer, \textbf{\[X\]} -- element of the stack with the address \textbf{X}): The program is located in cells with addresses from \textbf{0} to \textbf{127}. Each memory cell can contain exactly one command (including the constant value, if it exists). Be-fore beginning execution, the accumulator is set to the value to be processed, and reg-isters \textbf{IP} and \textbf{SP} are zeroed. The result of calculation is the value of the accumulator after the program stops. Given microprocessor program, write a program that calculates its result for each provided accumulator value. \InputFile The first line contains two integers \textbf{n} and \textbf{m}, separated by spaces, where \textbf{n} -- number of commands in the program, \textbf{m} -- number of values of accumulator for which you should make calculations. The subsequent \textbf{n} lines contain the commands in the following format: "Address of memory cells," "space" "command’s mnemonic" \["space", "argument."\] Command are listed sequentially from cell with address \textbf{0} to cell with address\textbf{ n-1}. The program is followed by \textbf{m} integers \textbf{a_i} -- initial values of the accumulator, which should be processed by microprocessor. The numbers are separated by spaces. \textbf{1} ≤ \textbf{n} ≤ \textbf{128}; \textbf{1} ≤ \textbf{m} ≤ \textbf{10^3}, \textbf{--2^59} ≤ \textbf{a_i} < \textbf{2^59}. All mnemonics are written with capital Latin letters, and a constant \textbf{X} is specified as a decimal number (possibly signed) ranged from \textbf{--2^59} ≤ \textbf{X} < \textbf{2^59}; for the \textbf{CALL} command \textbf{0} ≤ \textbf{X} ≤ \textbf{127}. The given program has a finite run time, and never overflows the stack. \OutputFile The first line of the output file should contain integer \textbf{m} -- the number of calculated values. Following \textbf{m} lines should contain the results of calculations for input values \textbf{a_i}, placed in the same order as \textbf{a_i},, one per line.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
6 2
0 ADD 9
1 CALL 4
2 SUB 3
3 RET
4 NEG
5 RET
1 10
Выходные данные #1
2
13
22