참외밭 - 2477

2025. 2. 12. 15:40PS/백준

문제

https://www.acmicpc.net/problem/2477

느낀점

상당히 애를 많이 먹었다.. 큰 부분에서 작은 부분을 빼줘야한다는 것은 알았지만, 작은 부분을 어떻게 계산할지에 대해 많이 고민하였다. 돌아가는 경로를 곱씹으면서 규칙을 파악하여 문제를 해결하였다.

풀이

#include <iostream>
#include <vector>
#include <map>

int main()
{
    int K, direction, length;
    std::cin >> K;
    std::vector<std::pair<int, int>> move;
    std::map<int, int> directionCount;
    int bigArea = 1;
    int smallArea = 1;

    for (int i = 0; i < 6; i++)
    {
        std::cin >> direction >> length;
        directionCount[direction - 1]++;
        move.push_back({direction, length});
    }

    for (int i = 0; i < 6; i++)
    {
        if (directionCount[move[i].first - 1] == 1)
        {
            bigArea *= move[i].second;
            smallArea *= move[(i + 3) % 6].second;
        }
    }
    std::cout << (bigArea - smallArea) * K;

    return 0;
}

'PS > 백준' 카테고리의 다른 글

미로 만들기 - 1347  (0) 2025.02.12
창고 다각형 - 2304  (0) 2025.02.12
결혼식 - 5567  (0) 2025.02.12
점프 점프 - 11060  (0) 2025.02.12
양 한마리... 양 두마리... - 11123  (0) 2025.02.12