CF133B.Unary

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Unary is a minimalistic Brainfuck dialect in which programs are written using only one token.

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:

  • ">"  →  1000,
  • "<"  →  1001,
  • "+"  →  1010,
  • "-"  →  1011,
  • "."  →  1100,
  • ","  →  1101,
  • "["  →  1110,
  • "]"  →  1111.

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.

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).

一元码(Unary)是一种极简的 Brainfuck 方言,其程序仅使用一种符号编写。

Brainfuck 程序使用 8 种指令:+、-、[、]、<、>、. 和 ,(本题中这些指令的具体含义无关紧要)。一元码程序由 Brainfuck 程序通过以下算法生成:首先,依据下表将每条指令替换为对应的二进制码:

  • >  →  1000,
  • <  →  1001,
  • +  →  1010,
  • -  →  1011,
  • .  →  1100,
  • ,  →  1101,
  • [  →  1110,
  • ]  →  1111.

接着,按原 Brainfuck 程序中指令的顺序,将所得二进制码连接成一个二进制数。最后,将该二进制数用一进制(unary)记数法表示——此即与原 Brainfuck 程序等价的一元码程序。

现给定一个 Brainfuck 程序。你的任务是计算其对应一元码程序的长度,并输出该长度对 10000031000003(即 106+310^6 + 3)取模的结果。

输入格式

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 ",".

输入将包含一行字符串 p,表示一个 Brainfuck 程序。字符串 p 的长度在 1 到 100 个字符之间(含端点)。p 的每个字符均为 "+", "-", "[", "]", "<", ">", "." 或 "," 中的一个。

输出格式

Output the size of the equivalent Unary program modulo 1000003 (106 + 3).

输出等价的一元程序的大小对 1000003(即 106+310^6 + 3)取模的结果。

输入输出样例

  • 输入#1

    ,.

    输出#1

    220
  • 输入#2

    ++++[&gt;,.&lt;-]

    输出#2

    61425

说明/提示

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.

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.

在一进制(unary)数字系统中表示一个数 nn,只需连续写出 nn 个 1。例如,5 在一进制中表示为 11111。

在第一个示例中,将 Brainfuck 指令替换为对应的二进制码后,得到 1101 1100。将这些二进制码连接起来,我们得到二进制数 11011100,即十进制数 220。这恰好等于等价的一进制程序中的符号(token)总数。

输入解题思路,AI测评打分。不知道怎么写?

首页