6771.Gray Code

Time Limit: 1s Memory Limit: 512MB

A Gray code is a list of all $2^n$ bit strings of length $n$ , where any two successive strings differ in exactly one bit (i.e., their Hamming distance is one).

Your task is to create a Gray code for a given length $n$ .

Input Format(From the terminal/stdin)

The only input line has an integer $n$ .

  • $1 \le n \le 16$

Output Format(To the terminal/stdout)

Print $2^n$ lines that describe the Gray code. You can print any valid solution.

Sample Input

Copy
2
 \n

Sample Output special judge

Copy
00
01
11
10
  \n
  \n
  \n
  \n
Source: CSES, Introductory Problems, 2205

Submit

请先 登录

© 2025 FAQs