Submission #226692

# Submission time Handle Problem Language Result Execution time Memory
226692 2020-04-24T22:09:57 Z DavidDamian Konj (COCI19_konj) C++11
63 / 70
96 ms 21240 KB
#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=299-b;
        c=c-1;
        d=299-d;
        //cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
        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=299-y;
    for(int i=0;i<n;i++){
        //cout<<A[i].a<<" "<<A[i].b<<" "<<A[i].c<<" "<<A[i].d<<endl;
        Sort(A[i].a,A[i].b,A[i].c,A[i].d);
        //cout<<A[i].a<<" "<<A[i].b<<" "<<A[i].c<<" "<<A[i].d<<endl;
        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

konj.cpp: In function 'int main()':
konj.cpp:118:35: warning: 'lastCol' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int firstRow,firstCol,lastRow,lastCol;
                                   ^~~~~~~
konj.cpp:118:18: warning: 'firstCol' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int firstRow,firstCol,lastRow,lastCol;
                  ^~~~~~~~
konj.cpp:118:27: warning: 'lastRow' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int firstRow,firstCol,lastRow,lastCol;
                           ^~~~~~~
konj.cpp:118:9: warning: 'firstRow' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int firstRow,firstCol,lastRow,lastCol;
         ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2560 KB Output is correct
2 Correct 6 ms 2560 KB Output is correct
3 Runtime error 96 ms 21240 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Correct 6 ms 2560 KB Output is correct
5 Correct 6 ms 2560 KB Output is correct
6 Correct 6 ms 2560 KB Output is correct
7 Correct 6 ms 2560 KB Output is correct
8 Correct 6 ms 2560 KB Output is correct
9 Correct 6 ms 2560 KB Output is correct
10 Correct 6 ms 2560 KB Output is correct