codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

133B.md (1948B)


      1 Source: https://codeforces.com/problemset/problem/133/B
      2 
      3 B. Unary
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.
     22 
     23 Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:
     24 
     25 * ">"  →  1000,
     26 * "<"  →  1001,
     27 * "+"  →  1010,
     28 * "-"  →  1011,
     29 * "."  →  1100,
     30 * ","  →  1101,
     31 * "["  →  1110,
     32 * "]"  →  1111.
     33 
     34 Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.
     35 
     36 You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).
     37 
     38 Input
     39 
     40 The input will consist of a single line *p* which gives a Brainfuck program. String *p* will contain between 1 and 100 characters, inclusive. Each character of *p* will be "+", "-", "[", "]", "<", ">", "." or ",".
     41 
     42 Output
     43 
     44 Output the size of the equivalent Unary program modulo 1000003 (106 + 3).
     45 
     46 Examples
     47 
     48 Input
     49 
     50 ```
     51 ,.
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 220
     58 ```
     59 
     60 Input
     61 
     62 ```
     63 ++++[>,.<-]
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 61425
     70 ```
     71 
     72 Note
     73 
     74 To write a number *n* in unary numeral system, one simply has to write 1 *n* times. For example, 5 written in unary system will be 11111.
     75 
     76 In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program.