Gardening

면접 대비

시간 제한1초메모리 제한2048 MB

요약
정수 격자 위 단순 다각형의 꼭짓점이 주어질 때, 내부에 완전히 들어가는 격자 칸의 수를 세는 문제로, 픽의 정리에 따라 다각형의 넓이와 같다.
난이도

보통10점 중 6점

유형
기하, 수학, 구현, 배열
정답자
아직 제출이 없습니다

문제

Bob has an incredibly huge garden with lots of grass and beautiful flowers, but since he started training his programming skills for the SKP, he does not have that much time to maintain it any more. To reduce the time spent maintaining his garden, Bob selected an area of his garden where he wants to place square stone tiles. He subdivided his garden into a nn by nn square grid (1≤n≤1000)(1 \leq n \leq 1000) such that one stone tile fits exactly into one grid cell. Therefore, each tile must be placed inside exactly one grid cell.

The area Bob wants to fill with tiles is given as a sequence of mm points defining its perimeter. Each line segment between points p_ip\_i and p_i+1p\_{i+1} defines an edge of the area. Point p_0p\_0 is also connected to point p_m−1p\_{m-1}. In each cell within the defined perimeter, exactly one stone tile is placed. Bob now needs your help to count the number of stone tiles he needs to fill the entire designated area.

Figure 1 - Example testcase 2, where points given as input are highlighted.

입력

The first line of the input consists of one integer mm (4≤m≤1000)(4 \leq m \leq 1000): the number of points that define the perimeter of the selected area.

The following input consists of mm distinct lines with two space-separated integers x_ix\_i and y_iy\_i (1≤x_i,y_i≤1000)(1 \leq x\_i,y\_i \leq 1000): The coordinates of point p_ip\_i are (x_i,y_i)(x\_i,y\_i). The bottom left corner is defined as point (0,0)(0,0) and the top right corner is defined as point (n,n)(n,n).

출력

One line with the number of square tiles required to fill the entire designated area.

예제2

  1. 예제 1

    입력
    4
    6 14
    6 33
    19 33
    19 14
    
    예상 출력
    247
    
  2. 예제 2

    입력
    12
    5 1
    5 6
    10 6
    10 7
    1 7
    1 14
    14 14
    14 9
    18 9
    18 3
    12 3
    12 1
    
    예상 출력
    160