A. Binary Protocol

Codeforces
IDCF825A
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: * Each digit is represented with number of _'1'_ characters equal to the value of that digit (for _0_ it is zero ones). * Digits are written one by one in order corresponding to number and separated by single _'0'_ character. Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number. ## Input The first line contains one integer number _n_ (1 ≤ _n_ ≤ 89) — length of the string _s_. The second line contains string _s_ — sequence of _'0'_ and _'1'_ characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with _'1'_. ## Output Print the decoded number. [samples]
Polycarp 刚刚发明了一种用于数据传输的新二进制协议。他使用以下算法将正整数的十进制数编码为二进制字符串: 尽管 Polycarp 学会了如何编码数字,但他不知道如何将其解码回来。请帮助他计算出解码后的数字。 第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 89])——字符串 #cf_span[s] 的长度。 第二行包含字符串 #cf_span[s] —— 由 _'0'_ 和 _'1'_ 字符组成的序列,表示编码后的数字。保证该字符串对应的数字为正数且不超过 #cf_span[109]。字符串始终以 _'1'_ 开头。 请输出解码后的数字。 ## Input 第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 89])——字符串 #cf_span[s] 的长度。第二行包含字符串 #cf_span[s] —— 由 _'0'_ 和 _'1'_ 字符组成的序列,表示编码后的数字。保证该字符串对应的数字为正数且不超过 #cf_span[109]。字符串始终以 _'1'_ 开头。 ## Output 请输出解码后的数字。 [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be the length of the binary string. Let $ s = s_1 s_2 \dots s_n $ be a binary string with $ s_i \in \{0,1\} $, $ s_1 = 1 $. **Constraints** 1. $ 1 \leq n \leq 89 $ 2. $ s_i \in \{0,1\} $ for all $ i \in \{1, \dots, n\} $ 3. $ s_1 = 1 $ 4. The decoded number $ x \in \mathbb{Z}^+ $ satisfies $ 1 \leq x \leq 10^9 $ **Objective** Decode the binary string $ s $ into a positive integer $ x $ using the following rule: The string $ s $ is the **binary representation of the number $ x $**, interpreted as a standard binary number. That is, $$ x = \sum_{i=1}^{n} s_i \cdot 2^{n-i} $$
Samples
Input #1
3
111
Output #1
3
Input #2
9
110011101
Output #2
2031
API Response (JSON)
{
  "problem": {
    "name": "A. Binary Protocol",
    "description": {
      "content": "Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: *   Each digit is represented with n",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF825A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:\n\n*   Each digit is represented with n...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Polycarp 刚刚发明了一种用于数据传输的新二进制协议。他使用以下算法将正整数的十进制数编码为二进制字符串:\n\n尽管 Polycarp 学会了如何编码数字,但他不知道如何将其解码回来。请帮助他计算出解码后的数字。\n\n第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 89])——字符串 #cf_span[s] 的长度。\n\n第二行包含字符串 #cf_span[s] ——...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the length of the binary string.  \nLet $ s = s_1 s_2 \\dots s_n $ be a binary string with $ s_i \\in \\{0,1\\} $, $ s_1 = 1 $.\n\n**Constraints**  \n1. $ 1 \\leq ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments