개발자 톡
연습문제 톡
[한양대 HCPC 2023] Phi Squared
Phi Squared TC 1 ~ 10 오답 도와주세요.
- 등록일
- 2024-02-17 21:03:51
- 조회수
- 623
- 작성자
- mincheol6073
TC 1 ~ 10 통과 못하고 있는데, 도통 어디가 문제인지 모르겠습니다. 도와주시면 감사하겠습니다.
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); Deque<Node> nextDayQueue = new LinkedList<>(); Deque<Node> todayQueue = new LinkedList<>(); for(int i = 1 ; i < N + 1 ; i++) { int size = sc.nextInt(); todayQueue.addLast(new Node(i, size)); } while(todayQueue.size() > 1) { while(!todayQueue.isEmpty()) { Node node = todayQueue.pollFirst(); if(!nextDayQueue.isEmpty() && nextDayQueue.peekLast().size <= node.size) { Node lastNode = nextDayQueue.pollLast(); nextDayQueue.addLast(new Node(node.index, node.size + lastNode.size)); } else if (!todayQueue.isEmpty() && todayQueue.peekFirst().size <= node.size) { Node firstNode = todayQueue.pollFirst(); nextDayQueue.addLast(new Node(node.index, node.size + firstNode.size)); } else { nextDayQueue.addLast(node); } } todayQueue = nextDayQueue; nextDayQueue = new LinkedList<>(); } Node answer = todayQueue.pollFirst(); System.out.println(answer.size); System.out.println(answer.index); } static class Node { int index; long size; Node(int index, long size) { this.index = index; this.size = size; } } }
#[한양대_HCPC_2023]_Phi_Squared