Submission #112032

# Submission time Handle Problem Language Result Execution time Memory
112032 2019-05-17T05:59:47 Z fredbr Konj (COCI19_konj) C++17
70 / 70
99 ms 17528 KB
#include <bits/stdc++.h>

#define ff first
#define ss second

using namespace std;

int const maxn = 310;

char saida[maxn][maxn];

using ii = pair<int, int>;

int lx = 400, rx = 0, ly = 400, ry = 0;

vector<ii> v[maxn][maxn];
char vis[maxn][maxn];
char s[maxn][maxn];

void dfs(int x, int y) {
    if (vis[x][y]) return;

    lx = min(lx, x);
    ly = min(ly, y);
    rx = max(rx, x);
    ry = max(ry, y);

    vis[x][y] = 1;

    for (ii uu : v[x][y]) {
        int a = uu.first, b = uu.second;

        if (a == x) {
            if (b > y) {
                for (int i = y; i <= b; i++)
                    s[a][i] = '#';
            }
            else {
                for (int i = b; i <= y; i++)
                    s[a][i] = '#';
            }
        } else {
            if (a > x) {
                for (int i = x; i <= a; i++)
                    s[i][y] = '#';
            }
            else {
                for (int i = a; i <= x; i++)
                    s[i][y] = '#';
            }
        }

        dfs(a, b);
    }
}

bool cont(int x, int y, int a, int b, int c, int d) {
    if (b > d) {
        swap(a, c);
        swap(b, d);
    }

    if (a == c) {
        if (x == a and y >= b and y <= d) return true;
        return false;
    }
    else {
        if (a > c) {
            swap(a, c);
            swap(b, d);
        }
        if (y == b and x >= a and x <= c) return true;
        return false;
    }
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);

    memset(s, '.', sizeof(s));

    int n;
    cin >> n;

    vector<pair<ii,ii>> vv(n);

    for (int i = 0; i < n; i++) {
        int x, y, a, b;
        cin >> x >> y >> a >> b;

        v[x][y].push_back(ii{a, b});
        v[a][b].push_back(ii{x, y});

        vv[i] = {{x, y}, {a, b}};
    }

    int x, y;
    cin >> x >> y;

    for (int i = 0; i < n; i++) {
        if (cont(x, y, vv[i].ff.ff, vv[i].ff.ss, vv[i].ss.ff, vv[i].ss.ss)) {
            v[x][y].push_back(vv[i].ff);
            v[x][y].push_back(vv[i].ss);
        }
    }

    dfs(x, y);

    for (int j = ry; j >= ly; j--) {
        for (int i = lx; i <= rx; i++) {
            cout << s[i][j];
        }
        cout << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
3 Correct 99 ms 17528 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 3 ms 2688 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 4 ms 2688 KB Output is correct