# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
314121 | phathnv | Konj (COCI19_konj) | C++11 | 108 ms | 16504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |