Skip to content

Commit 20716f0

Browse files
committed
[Gold V] Title: 두 개의 탑, Time: 1236 ms, Memory: 20144 KB -BaekjoonHub
1 parent 13446f3 commit 20716f0

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# [Gold V] 두 개의 탑 - 2118
2+
3+
[문제 링크](https://www.acmicpc.net/problem/2118)
4+
5+
### 성능 요약
6+
7+
메모리: 20144 KB, 시간: 1236 ms
8+
9+
### 분류
10+
11+
누적 합, 두 포인터
12+
13+
### 제출 일자
14+
15+
2025년 6월 5일 18:52:23
16+
17+
### 문제 설명
18+
19+
<p>1번부터 N번까지의 지점이 있다. 각각의 지점들은 차례로, 그리고 원형으로 연결되어 있다. 이 지점들 중 두 곳에 두 개의 탑을 세우려고 하는데, 두 탑의 거리가 최대가 되도록 만들려고 한다.</p>
20+
21+
<p>지점들이 원형으로 연결되어 있기 때문에, 두 지점 사이에는 시계방향과 반시계방향의 두 경로가 존재한다. 두 지점 사이의 거리를 잴 때에는, 이러한 값들 중에서 더 작은 값을 거리로 한다.</p>
22+
23+
<p>연결되어 있는 두 지점 사이의 거리가 주어졌을 때, 두 탑의 거리의 최댓값을 계산하는 프로그램을 작성하시오.</p>
24+
25+
### 입력
26+
27+
<p>첫째 줄에 지점의 개수 N(2 ≤ N ≤ 50,000)이 주어진다. 다음 N개의 줄에는 차례로 두 지점 사이의 거리가 양의 정수로 주어진다. 전체 거리의 총 합은 1,000,000,000을 넘지 않는다.</p>
28+
29+
### 출력
30+
31+
<p>첫째 줄에 답을 출력한다.</p>
32+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
static int n;
7+
static int[] arr, cw, ccw;
8+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
public static void main(String[] args) throws Exception{
10+
inputSetting();
11+
System.out.println(findMaxLen());
12+
}
13+
14+
static int findMaxLen(){
15+
int answer = 0;
16+
17+
for(int i = 0; i < n; i++){
18+
for(int j = i + 1; j < n; j++){
19+
answer = Math.max(answer, Math.min(cw[j] - cw[i], cw[n] - (cw[j] - cw[i])));
20+
}
21+
}
22+
return answer;
23+
}
24+
25+
static void inputSetting() throws Exception{
26+
n = Integer.parseInt(br.readLine());
27+
arr = new int[n];
28+
cw = new int[n + 1];
29+
30+
for(int i = 0; i < n; i++){
31+
arr[i] = Integer.parseInt(br.readLine());
32+
cw[i + 1] += cw[i] + arr[i];
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)