logo AlgoBeat OnlineJudge
登录 注册

#206095. [ICPC 2018 WF] Triangles

内存限制:1024 MiB 时间限制:6000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 .

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!

输入格式

The first line of input contains two integers and , specifying the picture size, where is the number of rows of vertices and is the number of columns. Following this are 2r lines, each of them having at most 2c characters. Odd lines contain grid vertices (represented as lowercase characters) and zero or more horizontal edges, while even lines contain zero or more diagonal edges. Specifically, picture lines with numbers 4k have vertices in positions , . . . while lines with numbers 4k have vertices in positions , . . . . All possible vertices are represented in the input (for example, see how Figure I.1 is represented in Sample Input ) . 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.

输出格式

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

样例

样例输入 1

3 3
x---x
 \ /
  x
 / \
x   x

样例输出 1

1

样例输入 2

4 10
x   x---x---x   x
     \ /   / \
  x   x---x   x   x
     / \ / \   \
x   x---x---x---x
   /   / \   \ / \
  x---x---x---x---x

样例输出 2

12

数据范围与提示

Time limit: 6 s, Memory limit: 1024 MB.