메뉴 건너뛰기

Programing

BAEKJOON

17611

관리자 2019.12.21 19:30 조회 수 : 7

C++

#include <cstdio>

#include <algorithm>

#include <vector>

using namespace std;

struct Pos{

    int x;

    int y;

};

vector<Pos> vec;

int N;

int pos_x[1000010],pos_y[1000010];//-500000+500000

int main()

{

    scanf("%d",&N);

    vec.reserve(N);

    for(int i=0;i<N;i++){

        int a,b;

        scanf("%d %d",&a,&b);

        vec.push_back({a,b});

    }

    int ax,ay,bx,by;

    for(int i=0;i<N;i++){

        if(i==0){

            ax=vec[N-1].x;

            ay=vec[N-1].y;

        }else{

            ax=vec[i-1].x;

            ay=vec[i-1].y;

        }

 

        bx=vec[i].x;

        by=vec[i].y;

 

        if(ax!=bx){

        if(ax<bx){

            pos_x[ax+500000]++;

            pos_x[bx+500000]--;

        }else if(ax>bx){

            pos_x[bx+500000]++;

            pos_x[ax+500000]--;

        }

        }

        else if(ay!=by){

        if(ay<by){

            pos_y[ay+500000]++;

            pos_y[by+500000]--;

        }else if(ay>by){

            pos_y[by+500000]++;

            pos_y[ay+500000]--;

        }

        }

 

    }

    int level_x=0,level_y=0,max_x=-1,max_y=-1;

    for(int i=0;i<1000010;i++){

        level_x+=pos_x[i];

        level_y+=pos_y[i];

        max_x=max(max_x,level_x);

        max_y=max(max_y,level_y);

    }

    printf("%d",max(max_x,max_y));

    return 0;

}

번호 제목 글쓴이 날짜 조회 수
공지 안내사항 관리자 2019.12.21 163
45 2468 관리자 2019.12.21 8
44 2458 관리자 2020.04.11 44
43 2457 관리자 2020.04.11 47
42 2454 관리자 2020.04.11 43
41 2450 관리자 2020.04.11 40
40 2339 관리자 2020.04.11 41
39 2307 관리자 2019.12.21 8
38 2250 관리자 2019.12.21 8
37 2233 관리자 2019.12.21 6
36 2170 관리자 2019.12.21 7
35 2132 관리자 2019.12.21 7
34 2096 관리자 2019.12.21 8
33 2042 관리자 2020.04.11 45
32 2003 관리자 2020.04.11 39
31 1991 관리자 2019.12.21 8
30 1967 관리자 2019.12.21 6
29 1966 관리자 2020.04.11 45
28 1946 관리자 2020.04.11 39
27 1874 관리자 2020.04.11 43
26 1839 관리자 2020.04.11 44
» 17611 관리자 2019.12.21 7
24 1753 관리자 2019.12.21 8
23 1742 관리자 2020.04.11 6
22 1720 관리자 2020.04.11 6
21 16210 관리자 2020.04.11 57
20 16201 관리자 2020.04.11 44
19 15971 관리자 2019.12.21 6
18 14865 관리자 2019.12.21 8
17 14503 관리자 2019.12.21 7
16 14502 관리자 2019.12.21 6
위로