codeforces 919C

C. Seat Arrangements

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of the seats were occupied.

The classroom contains n rows of seats and there are m seats in each row. Then the classroom can be represented as an n × m matrix. The character '.' represents an empty seat, while '*' means that the seat is occupied. You need to find k consecutive empty seats in the same row or column and arrange those seats for you and your friends. Your task is to find the number of ways to arrange the seats. Two ways are considered different if sets of places that students occupy differs.

Input

The first line contains three positive integers n, m, k (1 ≤ n, m, k ≤ 2 000), where n, m represent the sizes of the classroom and k is the number of consecutive seats you need to find.

Each of the next n lines contains m characters '.' or '*'. They form a matrix representing the classroom, '.' denotes an empty seat, and '*' denotes an occupied seat.

Output

A single number, denoting the number of ways to find k empty seats in the same row or column.

Examples

Input

Copy

2 3 2
**.
...

Output

Copy

3

Input

Copy

1 2 2
..

Output

Copy

1

Input

Copy

3 3 4
.*.
*.*
.*.

Output

Copy

0

Note

In the first sample, there are three ways to arrange those seats. You can take the following seats for your arrangement.

  • (1, 3), (2, 3)
  • (2, 2), (2, 3)
  • (2, 1), (2, 2)


集训应该写出来的题目

题解:先遍历行,再遍历列,做前缀和,最后叠加。

#include<bits/stdc++.h>
using namespace std;
const int N = 2010;
int n,m,k,ans = 0;
char temp[N];
int mat[N][N],sumR[N][N],sumC[N][N];
int main ()
{
  scanf("%d %d %d",&n,&m,&k);
  for(int i= 1;i<=n;i++)
  {
    scanf("%s",temp+1);//先把行输入进去
    for(int j =1;j<=m;j++)
      {
        if(temp[j] == '*')//再在某一确定的行中寻找列的
         mat[i][j] = 0;//如果是*则记为是0
        else mat[i][j] = 1;//否则是1
      }
  }
  for(int i =1;i<=n;i++)
   for(int j= 1;j<=m;j++)
    sumR[i][j] = sumR[i][j-1]+mat[i][j];//做行的前缀和
  for(int i= 1;i<=m;i++)
    for(int j= 1;j<=n;j++)
     sumC[i][j] = sumC[i][j-1] + mat[j][i];//做列的前缀和
  for(int i =1;i<=n;i++)
   for(int j= 1;j<=m;j++)
    {
      if(sumR[i][j]-sumR[i][j-k] == k)
       ans++;//当j到j-k的区间等于k时就存在一个答案。即每隔k格距离就看一下是否与k相等
    }
  for(int i=1;i<=m;i++)
    for(int j= 1;j<=n;j++)
     {
       if(sumC[i][j] - sumC[i][j-k] == k)
        ans++;
     }
  if(k == 1)
  ans/=2;//k == 1 计算了两遍,除以2
  printf("%d\n",ans);
  return 0;
}

猜你喜欢

转载自blog.csdn.net/strategist_614/article/details/81190474