Back to problems Sign in to unlock
Codeforces
Easy
Arrays
Strings
Simulation
Fox And Snake
Print a fixed snake-like pattern of # characters on an n × m grid.
Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement
Problem
You are given two integers n and m. Print an n × m grid that looks like a snake:
- Every row has exactly
mcharacters. - Rows with an odd 1-based index are completely filled with
#. - For even 1-based rows, place a single
#at one end and dots.everywhere else. - The single
#alternates between the right end and the left end on consecutive even rows.
This creates a continuous snake path when the rows are stacked together.
Task
Construct and print the grid exactly in the required format.
Input Format
- A single line containing two integers
nandm.
Output Format
- Print
nlines. - Each line must contain exactly
mcharacters consisting only of#and..
Constraints
1 ≤ n, m.- The grid dimensions are small enough to print directly.
Examples
Sample cases returned by the problem API.
Example 1
Input
3 3
Output
### ..# ###
Explanation
Row 1 is full. Row 2 has a single # on the right. Row 3 is full again.
Example 2
Input
4 5
Output
##### ....# ##### #....
Explanation
Even rows alternate the position of the single # between the right and left ends.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.