Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 프로그래머스
- baekjoon
- Unreal Engine5
- UE5
- 오블완
- UnrealEngine5
- IFileDialog
- 팰린드롬 만들기
- RootMotion
- NRVO
- UnrealEngine4
- 줄 세우기
- softeer
- DirectX11
- 언리얼엔진5
- GeeksForGeeks
- winapi
- 1563
- Programmers
- C
- Frustum
- 티스토리챌린지
- RVO
- const
- 백준
- 2294
- algorithm
- directx
- DeferredRendering
- C++
Archives
- Today
- Total
Game Develop
[Algorithm] Programmers :: 혼자 놀기의 달인 본문
https://school.programmers.co.kr/learn/courses/30/lessons/131130
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
bool visited[101] = { false };
vector<int> answers;
void DFS(int boxNum, int groupNum, int count, vector<int>& cards)
{
if (visited[boxNum])
{
answers.push_back(count);
return;
}
visited[boxNum] = true;
DFS(cards[boxNum]-1, groupNum, count+1, cards);
}
int solution(vector<int> cards)
{
int groupNum = -1;
for (int i = 0; i < cards.size(); ++i)
{
if (visited[i]) continue;
++groupNum;
visited[i] = true;
DFS(cards[i]-1, groupNum, 1, cards);
}
if (answers.size() == 1) return 0;
sort(answers.rbegin(), answers.rend());
return answers[0] * answers[1];
}
|
cs |
'Algorithm > Programmers' 카테고리의 다른 글
[Algorithm] Programmers :: 택배상자 (0) | 2023.06.08 |
---|---|
[Algorithm] Programmers :: 연속 부분 수열 합의 개수 (0) | 2023.06.07 |
[Algorithm] Programmers :: 양궁대회 (1) | 2023.06.06 |
[Algorithm] Programmers :: 할인 행사 (0) | 2023.06.05 |
[Algorithm] Programmers :: n^2 배열 자르기 (0) | 2023.06.05 |