406667: GYM102482 I Triangles

Memory Limit:1024 MB Time Limit:6 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. Trianglestime limit per test6 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard output

For your trip to Beijing, you have brought plenty of puzzle books, many of them containing challenges like the following: how many triangles can be found in Figure I.1?

Figure I.1: Illustration of Sample Input 2.

While these puzzles keep your interest for a while, you quickly get bored with them and instead start thinking about how you might solve them algorithmically. Who knows, maybe a problem like that will actually be used in this year's contest. Well, guess what? Today is your lucky day!Input

The first line of input contains two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le 3 000$$$, $$$1 \le c \le 6 000$$$), specifying the picture size, where $$$r$$$ is the number of rows of vertices and $$$c$$$ is the number of columns. Following this are $$$2r - 1$$$ lines, each of them having at most $$$2c - 1$$$ characters. Odd lines contain grid vertices (represented as lowercase x characters) and zero or more horizontal edges, while even lines contain zero or more diagonal edges. Specifically, picture lines with numbers $$$4k + 1$$$ have vertices in positions $$$1, 5, 9, 13, \ldots$$$ while lines with numbers $$$4k + 3$$$ have vertices in positions $$$3, 7, 11, 15, \ldots$$$. All possible vertices are represented in the input (for example, see how Figure I.1 is represented in Sample Input 2). Horizontal edges connecting neighboring vertices are represented by three dashes. Diagonal edges are represented by a single forward slash ('/') or backslash ('\') character. The edge characters will be placed exactly between the corresponding vertices. All other characters will be space characters. Note that if any input line could contain trailing whitespace, that whitespace may be omitted.

Output

Display the number of triangles (of any size) formed by grid edges in the input picture.

ExamplesInput
3 3
x---x
 \ /
  x
 / \
x   x
Output
1
Input
4 10
x   x---x---x   x
     \ /   / \
  x   x---x   x   x
     / \ / \   \
x   x---x---x---x
   /   / \   \ / \
  x---x---x---x---x
Output
12

加入题单

上一题 下一题 算法标签: