Submission #224955

# Submission time Handle Problem Language Result Execution time Memory
224955 2020-04-19T06:54:14 Z kartel Konj (COCI19_konj) C++14
70 / 70
70 ms 5112 KB
#include <bits/stdc++.h>
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define F first
#define S second
#define pb push_back
#define M ll(998244353)
#define inf ll(2e9+7)
#define N ll(200500)
#define sz(x) x.size()
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
#define el '\n'
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> os;

char ans[301][301];
int a[301][301];
int xl[N], xr[N], yl[N], yr[N], pr[N], ra[N], i, j, x, y, k, n, n1, m1;

int f(int x) {return ((pr[x] == x) ? x : (pr[x] = f(pr[x])));}

void link(int x, int y)
{
    x = f(x);
    y = f(y);
    if (x > y) swap(x, y);
    if (ra[x] < ra[y]) pr[x] = y;
    else
    {
        pr[y] = x;
        if (ra[x] == ra[y]) ra[y]++;
    }
}

int main()
{
//    in("input.txt");
//    out("output.txt");

    ios_base::sync_with_stdio(false);
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;

    for (i = 1; i <= n; i++) pr[i] = i, ra[i] = 1;

    for (i = 1; i <= n; i++)
    {
        cin >> xl[i] >> yl[i] >> xr[i] >> yr[i];

        if (xl[i] > xr[i]) swap(xl[i], xr[i]);
        if (yl[i] > yr[i]) swap(yl[i], yr[i]);

        for (x = xl[i]; x <= xr[i]; x++)
          for (y = yl[i]; y <= yr[i]; y++)
        {
            if (a[x][y] == 0) a[x][y] = i;
                         else link(a[x][y], i);
        }
    }

    for (i = 0; i <= 300; i++)
      for (j = 0; j <= 300; j++) ans[i][j] = '.';

    cin >> x >> y;

    k = a[x][y];
    int n2 = 300, m2 = 300;

    for (i = 1; i <= n; i++)
    {
        if (f(i) != f(k)) continue;

        n1 = max(n1, xr[i]);
        m1 = max(m1, yr[i]);

        n2 = min(n2, xl[i]);
        m2 = min(m2, yl[i]);

        for (x = xl[i]; x <= xr[i]; x++)
          for (y = yl[i]; y <= yr[i]; y++) ans[y][x] = '#';


    }

    int f = 0;

    for (i = m1; i >= m2; i--)
        {
            for (j = n2; j <= n1; j++) cout << ans[i][j];

            cout << el;
        }

}

Compilation message

konj.cpp: In function 'int main()':
konj.cpp:95:9: warning: unused variable 'f' [-Wunused-variable]
     int f = 0;
         ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 70 ms 5112 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 640 KB Output is correct