-
Notifications
You must be signed in to change notification settings - Fork 4
[23주차] 배수빈 #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
[23주차] 배수빈 #316
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ad721e5
[배수빈] 1135 뉴스 전하기
baexxbin 5a90b2e
[배수빈] 389479 서버 증설 횟수_250220
baexxbin 593bb55
배수빈: [BOJ] 1450 냅색문제_250221
baexxbin 93bed93
배수빈: [SQL] 물고기 종류 별 대어 찾기_250220
baexxbin 37c9db7
배수빈: [BOJ] 고대 문명 유적 탐사_250222
baexxbin 0f68063
배수빈: [BOJ] 19237 어른 상어_250223(미해결)
baexxbin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
BOJ/1000-5000번/SB_1135.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
public class SB_1135 { | ||
static int N; | ||
static List<List<Integer>> underling = new ArrayList<>(); | ||
|
||
private static int call(int node) { | ||
ArrayList<Integer> lst = new ArrayList<>(); | ||
|
||
if (underling.get(node).isEmpty()) { // 리프노드면 0반환 | ||
return 0; | ||
} | ||
|
||
for (int ud : underling.get(node)) { | ||
lst.add(call(ud)); // 각 부하들의 전화단계 구하기 | ||
} | ||
|
||
lst.sort(Collections.reverseOrder()); | ||
for (int i = 0; i < lst.size(); i++) { | ||
lst.set(i, lst.get(i) + i + 1); | ||
} | ||
|
||
return Collections.max(lst); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 헉 신기한 문법이네요.. 최댓값을 반환해주는건가 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 리스트에서 Collections의 max를 통해 간단하게 최대값을 구할 수 있더라구요! |
||
} | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
N = Integer.parseInt(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
underling.add(new ArrayList<>()); | ||
} | ||
|
||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < N; i++) { | ||
int boss = Integer.parseInt(st.nextToken()); | ||
if (boss==-1) continue; | ||
underling.get(boss).add(i); | ||
} | ||
|
||
System.out.println(call(0)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.