백준 문제/자료구조

[백준] 9375번 패션왕 신해빈

dubu0721 2025. 3. 25. 15:21

문제: 9375번: 패션왕 신해빈

basic-algo-lecture/workbook/0x15.md at master · encrypted-def/basic-algo-lecture

 

basic-algo-lecture/workbook/0x15.md at master · encrypted-def/basic-algo-lecture

바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.

github.com

 

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <unordered_set>
#include <unordered_map>
#include <queue>

using namespace std;

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;
    while (t-- > 0) {
        unordered_map<string, int> items;
        int n;
        cin >> n;

        for (int i = 0; i < n; i++) {
            string name, type;
            cin >> name >> type;

            // 같은 이름의 의상이 주어지는 경우는 없으니까 중복 생각하지 말고 걍 +1 해줘
            items[type] = items[type] + 1;
        }

        long long tmp = 1;
        for (pair<string, int> item : items) {
            tmp *= ((long long)item.second + 1);
        }
        cout << tmp - 1 << "\n";
    }

    return 0;
}

 

^0^ 중복된 이름의 의상이 주어지는 경우는 없으니까 이름이 중복되는 경우는 생각하지 않아도 된다.

 

그러면 솔직히 문제는 너무 쉽게 풀리긴 한다.. 그냥 map 에 다 저장해놓은 다음에 마지막에 for 문 돌면서 tmp 값에 곱해주고 마지막에 1 빼면 된다.