c++UNIQUE VISION Programming Contest 2023 Spring(AtCoder Beginner Contest 300)C - Cross

C - Cross

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300300 points

Problem Statement

We have a grid with �H horizontal rows and �W vertical columns. We denote by (�,�)(i,j) the cell at the �i-th row from the top and �j-th column from the left of the grid.
Each cell in the grid has a symbol # or . written on it. Let �[�][�]C[i][j] be the character written on (�,�)(i,j). For integers �i and �j such that at least one of 1≤�≤�1≤i≤H and 1≤�≤�1≤j≤W is violated, we define �[�][�]C[i][j] to be ..

(4�+1)(4n+1) squares, consisting of (�,�)(a,b) and (�+�,�+�),(�+�,�−�),(�−�,�+�),(�−�,�−�)(a+d,b+d),(a+d,b−d),(a−d,b+d),(a−d,b−d) (1≤�≤�,1≤�)(1≤d≤n,1≤n), are said to be a cross of size �n centered at (�,�)(a,b) if and only if all of the following conditions are satisfied:

  • �[�][�]C[a][b] is #.
  • �[�+�][�+�],�[�+�][�−�],�[�−�][�+�]C[a+d][b+d],C[a+d][b−d],C[a−d][b+d], and �[�−�][�−�]C[a−d][b−d] are all #, for all integers �d such that 1≤�≤�1≤d≤n,
  • At least one of �[�+�+1][�+�+1],�[�+�+1][�−�−1],�[�−�−1][�+�+1]C[a+n+1][b+n+1],C[a+n+1][b−n−1],C[a−n−1][b+n+1], and �[�−�−1][�−�−1]C[a−n−1][b−n−1] is ..

For example, the grid in the following figure has a cross of size 11 centered at (2,2)(2,2) and another of size 22 centered at (3,7)(3,7).

The grid has some crosses. No # is written on the cells except for those comprising a cross.
Additionally, no two squares that comprise two different crosses share a corner. The two grids in the following figure are the examples of grids where two squares that comprise different crosses share a corner; such grids are not given as an input. For example, the left grid is invalid because (3,3)(3,3) and (4,4)(4,4) share a corner.

Let �=min⁡(�,�)N=min(H,W), and ��Sn​ be the number of crosses of size �n. Find �1,�2,…,��S1​,S2​,…,SN​.

Constraints

  • 3≤�,�≤1003≤H,W≤100
  • �[�][�]C[i][j] is # or ..
  • No two different squares that comprise two different crosses share a corner.
  • �H and �W are integers.

Input

The input is given from Standard Input in the following format:

�H �W
�[1][1]�[1][2]…�[1][�]C[1][1]C[1][2]…C[1][W]
�[2][1]�[2][2]…�[2][�]C[2][1]C[2][2]…C[2][W]
⋮⋮
�[�][1]�[�][2]…�[�][�]C[H][1]C[H][2]…C[H][W]

Output

Print �1,�2,…S1​,S2​,…, and ��SN​, separated by spaces.


Sample Input 1 Copy

5 9
#.#.#...#
.#...#.#.
#.#...#..
.....#.#.
....#...#

Sample Output 1 Copy

1 1 0 0 0

As described in the Problem Statement, there are a cross of size 11 centered at (2,2)(2,2) and another of size 22 centered at (3,7)(3,7).


Sample Input 2 Copy

3 3
...
...
...

Sample Output 2 Copy

0 0 0

There may be no cross.


Sample Input 3 Copy

3 16
#.#.....#.#..#.#
.#.......#....#.
#.#.....#.#..#.#

Sample Output 3 Copy

3 0 0

Sample Input 4 Copy

15 20
#.#..#.............#
.#....#....#.#....#.
#.#....#....#....#..
........#..#.#..#...
#.....#..#.....#....
.#...#....#...#..#.#
..#.#......#.#....#.
...#........#....#.#
..#.#......#.#......
.#...#....#...#.....
#.....#..#.....#....
........#.......#...
#.#....#....#.#..#..
.#....#......#....#.
#.#..#......#.#....#

Sample Output 4 Copy

5 0 1 0 0 0 1 0 0 0 0 0 0 0 0

AC:(c++)

#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int N = 110, INF = 100000;
char g[N][N];
int n, m;
int dx[4] = {-1, -1, 1, 1}, dy[4] = {-1, 1, -1, 1};
int dfs(int x, int y)
{
    int res = INF;
    for (int i = 0; i < 4; i ++ )
    {
        int a = x, b = y;
        int cnt = -1;
        while (a >= 1 && b >= 1 && a <= n && b <= m && g[a][b] == '#')
        {
            cnt ++;
            a += dx[i]; b += dy[i];
        }
        res = min(res, cnt);
    }
    return res;
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i ++ )
        cin >> g[i] + 1;

    map<int, int> ans;
    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            if (g[i][j] == '#')ans[dfs(i, j)] += 1;

    for (int i = 1; i <= min(n, m); i ++ ) cout << ans[i] << ' ';
    cout << endl;
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

浪子小院

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值