Submission #1100259

# Submission time Handle Problem Language Result Execution time Memory
1100259 2024-10-13T11:00:32 Z vjudge1 Maxcomp (info1cup18_maxcomp) C++17
0 / 100
1 ms 508 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n, m;
vector<vector<int>> matrix;
vector<vector<bool>> visited;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

bool isValid(int x, int y) {
    return x >= 0 && x < n && y >= 0 && y < m;
}

void dfs(int x, int y, int& sum, int& count) {
    visited[x][y] = true;
    sum += matrix[x][y];
    count++;

    for (int dir = 0; dir < 4; ++dir) {
        int nx = x + dx[dir];
        int ny = y + dy[dir];
        if (isValid(nx, ny) && !visited[nx][ny]) {
            dfs(nx, ny, sum, count);
        }
    }
}

int main() {
    cin >> n >> m;
    matrix.resize(n, vector<int>(m));
    visited.resize(n, vector<bool>(m, false));

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

    int maxValue = -1e9;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (!visited[i][j]) {
                int sum = 0, count = 0;
                dfs(i, j, sum, count);
                if (count > 0) {
                    maxValue = max(maxValue, sum - count);
                }
            }
        }
    }

    cout << maxValue << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -