Skip to content

[1주차] 이혜원 #3

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 13 commits into from
Sep 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
이혜원: [BOJ] 3020 개똥벌레_240911
  • Loading branch information
icegosimperson committed Sep 11, 2024
commit b9f8fc0d444cecab537dd0cfdc31c700b6b58d86
43 changes: 43 additions & 0 deletions BOJ/1000-10000번/HW_3020.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.util.Scanner;

// 시간 복잡도 : 시간 제한 1초, 장애물의 크기 : O(NlogN)
public class HW_3020 {
public static void main(String[] args) {
// 개똥벌레가 파괴해야 하는 장애물의 최솟값과 그러한 구간의 수 출력
Scanner sc = new Scanner(System.in);
int N = sc.nextInt(); // 동굴 크기 (장애물의 개수)
int H = sc.nextInt(); // 동굴 높이

int[] up = new int[H+1]; // 석순 장애물
int[] down = new int[H+1]; // 종유석 장애물

for (int n = 0; n < N; n++) {
int height = sc.nextInt(); // 장애물의 높이를 입력 받음
if (n % 2 == 0) {
up[height]++;
} else {
down[height]++;
}
}

// 석순과 종유석 누적합 계산
for(int i=H-1; i>=1; i--) {
up[i] += up[i + 1];
down[i] += down[i + 1];
}

int min = N;
int minCount = 0;

for(int i=1; i<H+1; i++){
int total = up[i] + down[H - i + 1];
if(total < min){
min = total; // 최솟값 갱신
minCount = 1;
} else if (total == min) {
minCount++;
}
}
System.out.println(min + " " + minCount);
}
}