G. Puzzling Language

Codeforces
IDCF952G
Time1000ms
Memory256MB
Difficulty
constructive algorithms
English · Original
Chinese · Translation
Formal · Original
In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck). The code in this language is a rectangular grid of characters '.' and 'X'. The code is converted to a Brainfuck program as follows: the characters are read in the usual order (top to bottom, left to right), and each 'X' character is converted a Brainfuck instruction to be executed. The instruction is defined by the left, top and right neighbors of the 'X' character using the following conversion table: <center>![image](https://espresso.codeforces.com/3df07c064c0d1b9fa0c4174054f138ca4d252e02.png)</center>You are given a string. Output a program in the described language which prints this string. You can download the language interpreter used for judging here: [https://assets.codeforces.com/rounds/952/puzzling-interpreter.cpp](https://assets.codeforces.com/rounds/952/puzzling-interpreter.cpp) (use C++11 to compile the code). Note several implementation details: * The first step of the language interpretation is conversion to a Brainfuck program, which is then executed. * The code must be rectangular, with all lines of the same length. It can have at most 10,000 lines and 10,000 columns, and can have at most 500,000 'X' characters. * The code has toroidal topology, i.e. the 'X' on the first line will have top neighbor in the last line. * Brainfuck interpreter has 30000 memory cells which store integers from 0 to 255 with increment/decrement done modulo 256. * Console input (_,_ command) is allowed in Brainfuck code but has no effect when executed. ## Input The input consists of a single string of characters with ASCII codes between 33 ('!') and 122 ('z'), inclusive. The length of the string is between 1 and 10 characters, inclusive. ## Output Output a program in the described language which, when executed, will print the given message. [samples] ## Note The example corresponds to the following Brainfuck program: - >+< >+++< >+++++< >+++++++< >+++++++++< >+++++++++++< < > . . . The triangular block decrements the first memory cell and sets the value of the second memory cell to 36 - the ASCII code of '$' character. The next line after the triangular block moves the memory pointer to the second memory cell, and the next three lines print the '$' character three times.
在本题中,你需要为一种源自 Brainfuck 的二维编程语言编写一个简单的代码生成器。 该语言的代码是一个由字符 '.' 和 'X' 组成的矩形网格。代码按常规顺序(从上到下,从左到右)读取,每个 'X' 字符会被转换为一个要执行的 Brainfuck 指令。该指令由 'X' 字符的左、上和右邻居根据以下转换表定义: 你被给定一个字符串。请输出一个上述语言的程序,该程序执行后会打印该字符串。 你可以在此处下载用于评测的语言解释器:https://assets.codeforces.com/rounds/952/puzzling-interpreter.cpp(请使用 C++11 编译代码)。请注意以下实现细节: 输入由一个字符串组成,其中字符的 ASCII 码在 33 ('!') 到 122 ('z') 之间(包含端点)。字符串长度在 1 到 10 之间(包含端点)。 请输出一个上述语言的程序,该程序执行后会打印给定的消息。 示例对应以下 Brainfuck 程序: 三角形块将第一个内存单元减一,并将第二个内存单元的值设为 36 —— 即 '$' 字符的 ASCII 码。三角形块后的下一行将内存指针移动到第二个内存单元,接下来的三行将 '$' 字符打印三次。 ## Input 输入由一个字符串组成,其中字符的 ASCII 码在 33 ('!') 到 122 ('z') 之间(包含端点)。字符串长度在 1 到 10 之间(包含端点)。 ## Output 请输出一个上述语言的程序,该程序执行后会打印给定的消息。 [samples] ## Note 示例对应以下 Brainfuck 程序: - >+< >+++< >+++++< >+++++++< >+++++++++< >+++++++++++<< >...三角形块将第一个内存单元减一,并将第二个内存单元的值设为 36 —— 即 '$' 字符的 ASCII 码。三角形块后的下一行将内存指针移动到第二个内存单元,接下来的三行将 '$' 字符打印三次。
Given a string $ s = s_1 s_2 \dots s_n $ of length $ 1 \leq n \leq 10 $, where each $ s_i \in \{ \text{ASCII } 33 \text{ to } 122 \} $, construct a rectangular grid of characters '.' and 'X' such that, when interpreted by the described 2D language (reading left-to-right, top-to-bottom, and mapping each 'X' to a Brainfuck instruction based on its left, top, and right neighbors via a fixed conversion table), the resulting Brainfuck program outputs $ s $. The grid must be designed so that the executed Brainfuck program: - Initializes memory cells appropriately, - Sets the value of memory cells to the ASCII codes of $ s_1, s_2, \dots, s_n $, - Outputs each character in sequence. The conversion table for 'X' instructions based on neighbor patterns is fixed and known (but not explicitly provided here); the solution must produce a valid grid that, under this mapping, generates a Brainfuck program equivalent to the required output. **Objective:** Output such a grid (as a list of strings, each representing a row) with minimal dimensions, using only '.' and 'X'.
Samples
Input #1
$$$
Output #1
.......X.......
......XXX......
.....XXXXX.....
....XXXXXXX....
...XXXXXXXXX...
..XXXXXXXXXXX..
.XXXXXXXXXXXXX.
...............
X.............X
X..............
X..............
X..............
API Response (JSON)
{
  "problem": {
    "name": "G. Puzzling Language",
    "description": {
      "content": "In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck). The code in this language is a rectangular grid",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF952G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "In this problem you will write a simple code generator for a 2D programming language derived from [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck).\n\nThe code in this language is a rectangular grid...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "在本题中,你需要为一种源自 Brainfuck 的二维编程语言编写一个简单的代码生成器。\n\n该语言的代码是一个由字符 '.' 和 'X' 组成的矩形网格。代码按常规顺序(从上到下,从左到右)读取,每个 'X' 字符会被转换为一个要执行的 Brainfuck 指令。该指令由 'X' 字符的左、上和右邻居根据以下转换表定义:\n\n你被给定一个字符串。请输出一个上述语言的程序,该程序执行后会打印该字符串。...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Given a string $ s = s_1 s_2 \\dots s_n $ of length $ 1 \\leq n \\leq 10 $, where each $ s_i \\in \\{ \\text{ASCII } 33 \\text{ to } 122 \\} $, construct a rectangular grid of characters '.' and 'X' such that...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments