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
- db
- 문제풀이
- COS PRO
- 코딩테스트
- dfs
- oracle
- priorityqueue
- math
- SWEA
- binary search
- 러닝일지
- 문제해결
- BOJ
- greedy
- 알고리즘
- 문자열
- Java
- 운동기록
- 코테
- MySQL
- 이분탐색
- BFS
- 건강
- 프로그래머스
- 자바
- DP
- 시뮬레이션
- 백준
- SQL
- 투포인터
Archives
- Today
- Total
슈콩
[SWEA] 진용이네 주차타워 본문


[문제]
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AW9j74FacD0DFAUY
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
[소스 코드]
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for(int tc=1;tc<=T;tc++) {
st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int[] cost = new int[n+1];
for(int i=1;i<=n;i++) {
cost[i] = Integer.parseInt(br.readLine());
}
int[] weight = new int[m+1];
for(int i=1;i<=m;i++) {
weight[i] = Integer.parseInt(br.readLine());
}
boolean[] canP = new boolean[n+1];
int[] parking = new int[m+1];
Queue<Integer> q = new LinkedList<>();
int result = 0;
for(int i=0;i<m*2;i++) {
int curr = Integer.parseInt(br.readLine());
if(curr>0) {
boolean check = false;
for(int j=1;j<=n;j++) {
if(!canP[j]) {
canP[j] = true;
parking[curr] = j;
check = true;
break;
}
}
if(!check)
q.offer(curr);
}
else {
curr *= -1;
canP[parking[curr]] = false;
result += weight[curr] * cost[parking[curr]];
if(!q.isEmpty()){
canP[parking[curr]] = true;
parking[q.poll()] = parking[curr];
}
}
}
System.out.println("#"+tc+" "+result);
}
}
}'Algorithms > SWEA' 카테고리의 다른 글
| [SWEA] 민석이의 과제 체크하기 (0) | 2025.11.12 |
|---|---|
| [SWEA] 현주의 상자 바꾸기 (3) | 2025.11.12 |
| [SWEA] 원 안의 점 (0) | 2025.11.12 |
| [SWEA] 최장 증가 부분 수열 (0) | 2025.11.12 |
| [SWEA] 8일차 - 암호문3 (0) | 2025.11.12 |