Submission #314121

# Submission time Handle Problem Language Result Execution time Memory
314121 2020-10-18T14:09:19 Z phathnv Konj (COCI19_konj) C++11
63 / 70
108 ms 16504 KB
#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define taskname "KONJ"

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int N = 2e5 + 1;
const int D = 301;

struct lineSegment{
    int a, b, c, d;
    bool contains(int x, int y){
        return (a <= x && x <= c && b <= y && d <= b);
    }
};

struct data{
    int x, y, ind;
    data(int _x, int _y, int _ind){
        x = _x;
        y = _y;
        ind = _ind;
    }
};

int n, x, y;
lineSegment a[N];

vector <data> adj[D][D];
bool vstSeg[N], vstCell[D][D], draw[D][D];

void readInput(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d;
        if (a[i].a > a[i].c)
            swap(a[i].a, a[i].c);
        if (a[i].b > a[i].d)
            swap(a[i].b, a[i].d);
    }
    cin >> x >> y;
}

void dfs(int x, int y){
    if (vstCell[x][y])
        return;
    vstCell[x][y] = 1;
    for(data d : adj[x][y]){
        vstSeg[d.ind] = 1;
        dfs(d.x, d.y);
    }
}

void solve(){
    for(int i = 1; i <= n; i++){
        adj[a[i].a][a[i].b].push_back(data(a[i].c, a[i].d, i));
        adj[a[i].c][a[i].d].push_back(data(a[i].a, a[i].b, i));
    }
    for(int i = 1; i <= n; i++)
        if (a[i].contains(x, y))
            dfs(a[i].a, a[i].b);
    int minX = D, maxX = 0, minY = D, maxY = 0;
    for(int i = 1; i <= n; i++){
        if (!vstSeg[i])
            continue;
        minX = min(minX, a[i].a);
        maxX = max(maxX, a[i].c);
        minY = min(minY, a[i].b);
        maxY = max(maxY, a[i].d);

        for(int x = a[i].a; x <= a[i].c; x++)
            for(int y = a[i].b; y <= a[i].d; y++)
                draw[x][y] = 1;
    }
    for(int y = maxY; y >= minY; y--){
        for(int x = minX; x <= maxX; x++)
            cout << (draw[x][y]? '#' : '.');
        cout << '\n';
    }
}

int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    readInput();
    solve();
    return 0;
}

Compilation message

konj.cpp: In function 'int main()':
konj.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   91 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
konj.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   92 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2560 KB Output is correct
2 Correct 2 ms 2560 KB Output is correct
3 Correct 108 ms 16504 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Incorrect 2 ms 2432 KB Output isn't correct
6 Correct 2 ms 2560 KB Output is correct
7 Correct 2 ms 2560 KB Output is correct
8 Correct 2 ms 2560 KB Output is correct
9 Correct 2 ms 2432 KB Output is correct
10 Correct 2 ms 2560 KB Output is correct