Fissura Perigosa

Problem Link

Solution by dudu100 pts

Code / Notes

// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int N, F;
vector<string> A;

void visit(int x, int y) {
    A[x][y] = '*';
    if (x-1 >= 0 and A[x-1][y]-'0' <= F and A[x-1][y] != '*') {
        visit(x-1, y);
    }
    if (y-1 >= 0 and A[x][y-1]-'0' <= F and A[x][y-1] != '*') {
        visit(x, y-1);
    }
    if (x+1 < N and A[x+1][y]-'0' <= F and A[x+1][y] != '*') {
        visit(x+1, y);
    }
    if (y+1 < N and A[x][y+1]-'0' <= F and A[x][y+1] != '*') {
        visit(x, y+1);
    }
}

int main() {
    cin >> N >> F;

    A.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    if (A[0][0]-'0' <= F) visit(0, 0);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << A[i][j];
        }
        cout << endl;
    }
}

Last updated 2 weeks, 3 days ago


« Back to problem