Little Jay

[C++] 백준 9375번 - 패션왕 신해빈 본문

알고리즘/BOJ

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

Jay, Lee 2022. 7. 2. 13:10

사실 내 힘으로 푼 문제는 아니다.

도저히 아이디어가 떠오르지 않아 다른 분들의 블로그를 참고했다.

식을 세우는데 어려움을 겪었는데 각 의상 종류별 + 1한 값의 곱에서 전체를 안입는 경우인 1을 빼주면 되는 식을 세우는 것이 결국 관건이었던 것 같다. 

이거를 도출해낸다는게 쉽지 않았고 Silver 3문제였는데도 이 아이디어를 30분 넘게 고민하다가 안되서 결국 참고했다. 

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int t, n;
string name, cloth;

int main() {

	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	cin >> t;
	while (t--) {
		cin >> n;
		map<string, int> mp;
		for (int i = 0; i < n; i++) {
			cin >> name >> cloth;

			if (mp.find(cloth) == mp.end()) {
				mp.insert({ cloth, 1 });
			}
			else {
				mp[cloth]++;
			}
		}

		int ans = 1;
		for (auto i : mp) {
			ans *= i.second + 1;
		}
		ans -= 1;
		cout << ans << endl;
	}

	return 0;
}
Comments