# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226693 | DavidDamian | Konj (COCI19_konj) | C++11 | 92 ms | 9336 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>
using namespace std;
void Sort(int& a,int& b,int& c,int& d)
{
if(c<a){
swap(a,c);
swap(b,d);
return;
}
else{
if(c==a){
if(d<b){
swap(a,c);
swap(b,d);
}
}
}
}
struct line{
int a,b,c,d;
} A[200005];
int n;
vector<int> bucket[305][305];
int color[200005];
int paint[305][305];
int x,y;
queue<int> Q;
void bfs()
{
while(Q.size()){
int u=Q.front();
Q.pop();
for(int v: bucket[ A[u].b ][ A[u].a ]){
if(color[v]==0){
color[v]=1;
Q.push(v);
}
}
for(int v: bucket[ A[u].d ][ A[u].c ]){
if(color[v]==0){
color[v]=1;
Q.push(v);
}
}
}
}
void print(int a,int b,int c,int d)
{
if(a==c){
for(int i=b;i<=d;i++){
paint[i][a]=1;
}
}
else{
for(int j=a;j<=c;j++){
paint[b][j]=1;
}
}
}
bool nothingRow(int i)
{
for(int j=0;j<300;j++){
if(paint[i][j]==1)
return false;
}
return true;
}
bool nothingCol(int j)
{
for(int i=0;i<300;i++){
if(paint[i][j]==1)
return false;
}
return true;
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
for(int i=0;i<n;i++){
int a,b,c,d;
cin>>a>>b>>c>>d;
a=a-1;
b=300-b;
c=c-1;
d=300-d;
A[i]={a,b,c,d};
bucket[b][a].push_back(i);
bucket[d][c].push_back(i);
}
cin>>x>>y;
x=x-1;
y=300-y;
for(int i=0;i<n;i++){
Sort(A[i].a,A[i].b,A[i].c,A[i].d);
if(A[i].a==A[i].c && A[i].a==x){
if(A[i].b<=y && y<=A[i].d){
color[i]=1;
Q.push(i);
}
}
else if(A[i].b==A[i].d && A[i].b==y){
if(A[i].a<=x && x<=A[i].c){
color[i]=1;
Q.push(i);
}
}
}
bfs();
for(int i=0;i<n;i++){
if(color[i]==1){ //Visited
print(A[i].a,A[i].b,A[i].c,A[i].d);
}
}
int firstRow,firstCol,lastRow,lastCol;
for(int i=0;i<305;i++){
if(!nothingRow(i)){
firstRow=i;
break;
}
}
for(int i=304;i>=0;i--){
if(!nothingRow(i)){
lastRow=i;
break;
}
}
for(int j=0;j<305;j++){
if(!nothingCol(j)){
firstCol=j;
break;
}
}
for(int j=304;j>=0;j--){
if(!nothingCol(j)){
lastCol=j;
break;
}
}
for(int i=firstRow;i<=lastRow;i++){
for(int j=firstCol;j<=lastCol;j++){
if(paint[i][j]==1) cout<<'#';
else cout<<'.';
}
cout<<'\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |