답안 #100320

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100320 2019-03-10T11:41:34 Z ozneroL Konj (COCI19_konj) C++14
70 / 70
264 ms 34680 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;


#define F first
#define S second

#define ERR 1e-9

#if !ONLINE_JUDGE && !EVAL
    #define dbg_var(x) cerr << #x << ": " << x << "\n";
    #define dbg_iter(x, y) cerr  << #x << ": " << print_iterable(x, y) << "\n";
#else
    #define dbg_var(x)
    #define dbg_iter(x, y)
#endif // ONLINE_JUDGE

template <typename T1, typename T2>
string print_iterable( T1 begin_iter, T2 end_iter){
    bool first = true;
    stringstream res;
    res << "[ ";
    for(; begin_iter != end_iter; ++begin_iter){
        if(!first) res << ", ";
        first = false;
        res << *begin_iter;
    }
    res << " ]";
    return res.str();
}

void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }

int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }

// constraints
const int MAXN = 310;
#define pb push_back

char grid[MAXN][MAXN];

void spread(int rI, int cI, int rF, int cF);

int minR, maxR, minC, maxC;

void print(){
    for(int i=maxR; i>=minR; i--){
        for(int j=minC; j<=maxC; j++)
            cout << grid[i][j];
        cout << "\n";
    }
}

struct segment{
    int cI, rI, cF, rF;
    bool isDraw;

    void draw(){
        if(!isDraw){
            isDraw = true;

            minR = min(minR, min(rI,rF));
            maxR = max(maxR, max(rI,rF));
            minC = min(minC, min(cI,cF));
            maxC = max(maxC, max(cI,cF));

            if(rI == rF){
                int cIt = cI, cFt = cF;
                if(cIt > cFt) swap(cIt, cFt);
                for(int i=cIt; i<=cFt; i++) grid[rI][i] = '#';
            }else{
                int rIt = rI, rFt = rF;
                if(rIt > rFt) swap(rIt, rFt);
                for(int i=rIt; i<=rFt; i++) grid[i][cI] = '#';
            }

            spread(rI, cI, rF, cF);
        }
    }

    bool equals(int rI2, int cI2, int rF2, int cF2){
        return rI == rI2 && cI == cI2 && rF2 == rF2 && cF == cF2;
    }

    void printS(){
        cout << rI << "," << cI << "  " << rF << "," << cF << "\n";
    }
};

vector<segment> containT;
vector<segment> endPoints[MAXN][MAXN];

void spread(int rI, int cI, int rF, int cF){
    for(segment & a : endPoints[rI][cI])
        if(!a.equals(rI, cI, rF, cF))
            a.draw();

    for(segment & a : endPoints[rF][cF])
        if(!a.equals(rI, cI, rF, cF))
            a.draw();
}

bool isBetween(int p, int c1, int c2){
    if(c1 > c2) swap(c1, c2);
    return c1 <= p && p <= c2;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    minR = minC = INT_MAX;

    int N = II();

    vector<segment> s(N);

    for(int i=0; i<N; i++){
        int cI, rI, cF, rF;
        cin >> cI >> rI >> cF >> rF;
        s[i] = {cI, rI, cF, rF, false};
        endPoints[rI][cI].pb(s[i]);
        endPoints[rF][cF].pb(s[i]);
    }

    int cT = II(), rT = II();

    for(segment & a : s){
        if(a.rI == a.rF && a.rI == rT && isBetween(cT, a.cI, a.cF)){
            /// horizontal segment
            containT.pb(a);
        }else if(a.cI == cT && isBetween(rT, a.rI, a.rF)){
            /// vertical segment
            containT.pb(a);
        }
    }

    memset(grid, '.', sizeof grid);

    /*for(int i=0; i<s.size(); i++){
        draw(s[i]);
    }*/

    for(segment & a : containT){
        a.draw();
    }

    print();

    return 0;
}

Compilation message

konj.cpp: In member function 'bool segment::equals(int, int, int, int)':
konj.cpp:89:46: warning: self-comparison always evaluates to true [-Wtautological-compare]
         return rI == rI2 && cI == cI2 && rF2 == rF2 && cF == cF2;
                                          ~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 264 ms 34680 KB Output is correct
4 Correct 4 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 4 ms 2688 KB Output is correct
7 Correct 4 ms 2688 KB Output is correct
8 Correct 4 ms 2688 KB Output is correct
9 Correct 4 ms 2688 KB Output is correct
10 Correct 5 ms 2688 KB Output is correct