답안 #226696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
226696 2020-04-24T22:23:32 Z DavidDamian Konj (COCI19_konj) C++11
70 / 70
89 ms 9336 KB
#include <bits/stdc++.h>
using namespace std;
///BFS
///Determine the final shape of the painting
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;
        b=301-b;
        d=301-d;
        A[i]={a,b,c,d};
        bucket[b][a].push_back(i);
        bucket[d][c].push_back(i);
    }
    cin>>x>>y;
    y=301-y;
    for(int i=0;i<n;i++){ //Checks if the point is in the line
        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; //Finds the minimum square
    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:114:35: warning: 'lastCol' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int firstRow,firstCol,lastRow,lastCol; //Finds the minimum square
                                   ^~~~~~~
konj.cpp:114:18: warning: 'firstCol' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int firstRow,firstCol,lastRow,lastCol; //Finds the minimum square
                  ^~~~~~~~
konj.cpp:114:27: warning: 'lastRow' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int firstRow,firstCol,lastRow,lastCol; //Finds the minimum square
                           ^~~~~~~
konj.cpp:114:9: warning: 'firstRow' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int firstRow,firstCol,lastRow,lastCol; //Finds the minimum square
         ^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2560 KB Output is correct
2 Correct 6 ms 2688 KB Output is correct
3 Correct 89 ms 9336 KB Output is correct
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