Submission #377559

# Submission time Handle Problem Language Result Execution time Memory
377559 2021-03-14T10:10:31 Z Araragi Selotejp (COCI20_selotejp) C++17
0 / 110
420 ms 1900 KB
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;

int hr[2][2] = {{1, 0}, {-1, 0}};
int vr[2][2] = {{0, 1}, {0, -1}};

int n, m;
map<int, map<int, bool> > hor, ver, vis;
map<int, map<int, int> > cntt;
char c[1001][11];

bool valid(int x, int y) {return (min(x, y) >= 1 && x <= n && y <= m && (!vis[x][y] && c[x][y] != '.'));}
bool validHor(int x, int y) {return (min(x, y) >= 1 && x <= n && y <= m && (!hor[x][y] || (hor[x][y] && !hor[x + 1][y] && c[x + 1][y] != '.')) && c[x][y] != '.');}
bool validVer(int x, int y) {return (min(x, y) >= 1 && x <= n && y <= m && (!ver[x][y] || (ver[x][y] && !ver[x][y + 1] && c[x][y + 1] != '.')) && c[x][y] != '.');}

queue<pair<int, int> > q;
int cnt, x, y;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            cin >> c[i][j];
        }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (!vis[i][j] && c[i][j] != '.')
            {
                q.push({i, j});
                cntt.clear();
                vis[i][j] = true;

                int skok_hor = 0, skok_ver = 0;

                hor = vis;
                ver = vis;

                while (!q.empty())
                {
                    skok_hor++;

                    x = q.front().F;
                    y = q.front().S;
                    q.pop();

                    cntt[x][y]++;

                    for (int i = 0; i < 2; i++)
                    {
                        int cx = x + hr[i][0];
                        int cy = y + hr[i][1];

                        if (validHor(cx, cy))
                        {
                            q.push({cx, cy});
                            hor[cx][cy] = true;
                        }
                    }
                }

                while (!q.empty())
                    q.pop();

                q.push({i, j});
                ver[i][j] = true;
                cntt.clear();

                while (!q.empty())
                {
                    x = q.front().F;
                    y = q.front().S;
                    q.pop();
                    cntt[x][y]++;
                    skok_ver++;

                    for (int i = 0; i < 2; i++)
                    {
                        int cx = x + vr[i][0];
                        int cy = y + vr[i][1];

                        if (validVer(cx, cy))
                        {
                            q.push({cx, cy});
                            ver[cx][cy] = true;
                        }
                    }
                }

                if (skok_ver == skok_hor && skok_hor == 1)
                {
                    cnt++;
                }
                else if (skok_ver < skok_hor)
                {
                    vis = hor;
                    cnt++;
                }
                else
                {
                    vis = ver;
                    cnt++;
                }

            }

    cout << cnt;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 420 ms 1900 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 420 ms 1900 KB Output isn't correct
3 Halted 0 ms 0 KB -