답안 #218150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218150 2020-04-01T10:25:10 Z Vimmer Emacs (COCI20_emacs) C++14
50 / 50
6 ms 384 KB
#include <bits/stdc++.h>

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 200005
#define M ll(1000000007)

using namespace std;

typedef long long ll;


int step[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}, x, y, n, m;

bool mk[200][200];

string a[200];

bool gd()
{
    for (x = 0; x < n; x++)
        for (y = 0; y < m; y++)
          if (a[x][y] == '*' && !mk[x][y]) {mk[x][y] = 1; return 1;}

    return 0;
}

queue <pair <int, int> > qr;

int main()
{
    //freopen("mining.in","r",stdin); freopen("mining.out","w",stdout);
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;

    for (int i = 0; i < n; i++) cin >> a[i];

    int ans = 0;

    while (gd())
    {
        qr.push({x, y});

        ans++;

        while (sz(qr) > 0)
        {
            int x = qr.front().F;

            int y = qr.front().S;

            qr.pop();

            for (int i = 0; i < 4; i++)
            {
                int cx = x + step[i][0];

                int cy = y + step[i][1];

                if (cx >= 0 && cx < n && cy >= 0 && cy < m && !mk[cx][cy] && a[cx][cy] == '*')
                {
                    mk[cx][cy] = 1;

                    qr.push({cx, cy});
                }
            }
        }
    }

    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct