-
Notifications
You must be signed in to change notification settings - Fork 0
[20250225] BOJ / P5 / 부분배열 고르기 / 권혁준 #179
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
Merged
Changes from all commits
Commits
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
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,89 @@ | ||
| ```java | ||
|
|
||
| import java.util.*; | ||
| import java.io.*; | ||
|
|
||
|
|
||
| class Main { | ||
|
|
||
| // IO field | ||
| static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
| static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
| static StringTokenizer st; | ||
|
|
||
| static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} | ||
| static int nextInt() {return Integer.parseInt(st.nextToken());} | ||
| static long nextLong() {return Long.parseLong(st.nextToken());} | ||
| static void bwEnd() throws Exception {bw.flush();bw.close();} | ||
|
|
||
| // Additional field | ||
|
|
||
| static int N; | ||
| static int[] r; | ||
| static long[] A, C; | ||
| static int[][] L; | ||
| static boolean[] V; | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
|
|
||
| ready(); | ||
| solve(); | ||
|
|
||
| bwEnd(); | ||
|
|
||
| } | ||
|
|
||
| static void ready() throws Exception{ | ||
|
|
||
| N = Integer.parseInt(br.readLine()); | ||
|
|
||
| r = new int[N]; | ||
| C = new long[N]; | ||
| A = new long[N]; | ||
| L = new int[N][2]; | ||
| V = new boolean[N]; | ||
| nextLine(); | ||
|
|
||
|
|
||
| for(int i=0;i<N;i++) { | ||
| r[i] = i; | ||
| A[i] = nextLong(); | ||
| C[i] = A[i]; | ||
| L[i][0] = (int)A[i]; | ||
| L[i][1] = i; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| static void solve() throws Exception{ | ||
|
|
||
| Arrays.sort(L, (a,b) -> b[0]-a[0]); | ||
|
|
||
| long ans = 0; | ||
| for(int[] now : L){ | ||
| int v = now[0], i = now[1]; | ||
| if(i>0 && V[i-1]){ | ||
| int x = f(i), y = f(i-1); | ||
| C[x] += C[y]; | ||
| r[y] = x; | ||
| } | ||
| if(i<N-1 && V[i+1]){ | ||
| int x = f(i), y = f(i+1); | ||
| C[x] += C[y]; | ||
| r[y] = x; | ||
| } | ||
| V[i] = true; | ||
| ans = Math.max(ans, v * C[f(i)]); | ||
|
Comment on lines
+65
to
+76
Contributor
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. 오 잘 이해는 못했지만, 이런 식으로도 풀 수 있군요 ㄷㄷ |
||
|
|
||
| } | ||
| bw.write(ans + "\n"); | ||
|
|
||
| } | ||
|
|
||
| static int f(int x) { | ||
| return x==r[x] ? x : (r[x]=f(r[x])); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| ``` | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
관점 분리 LGTM :)