Submission #1154073

#TimeUsernameProblemLanguageResultExecution timeMemory
1154073itslqSelotejp (COCI20_selotejp)C++20
0 / 110
1 ms324 KiB
#include <bits/stdc++.h>
using namespace std;

const pair<int, int> dirs[4]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int main() {
    int N, M, x = -1, y, nx, ny, T = 0;
    string S;
    cin >> N >> M;

    int grid[N][M];
    vector<vector<bool>> vis(N, vector<bool>(M, false));

    for (int i = 0; i < N; i++) {
        cin >> S;
        for (int j = 0; j < M; j++) {
            if (S[j] == '#') {
                x = i;
                y = j;
                grid[i][j] = 1;
            } else grid[i][j] = 0;
        }
    }

    if (x == -1) {
        cout << 0;
        return 0;
    }

    pair<int, int> curr, last;
    vector<pair<int, int>> tocheck(1, make_pair(x, y));

    while (!tocheck.empty()) {
        curr = tocheck.back();
        // cout << curr.first << " " << curr.second << endl;
        tocheck.pop_back();
        T++;

        for (auto dir: dirs) {
            nx = curr.first;
            ny = curr.second;
            last = make_pair(nx, ny);

            while (nx >= 0 && nx < N && ny >= 0 && ny < M) {
                // cout << "n" << nx << " " << ny << " " << vis[nx][ny] << endl;
                if (vis[nx][ny]) break;
                
                last = make_pair(nx, ny);
                vis[nx][ny] = 1;
                vis[curr.first][curr.second] = 0;
                nx += dir.first;
                ny += dir.second;
            }

            if (last.first != curr.first || last.second != curr.second) tocheck.push_back(last);
        }

        vis[curr.first][curr.second] = 1;
    }

    cout << T;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...