Etc/알고리즘

[softeer] 6270

jjuni_96 2024. 8. 2. 21:13
728x90

문제

 

 

제약조건

 

 

메모리 제약

 

입/출력

 

문제 분석

단순 구현

1. 제한속도, 실제속도 Map 생성
2. 제한속도, 실제속도 각 점들을 하나의 배열에 생성
3. 각 점들에서 "실제속도 - 제한속도 > 0" 인 구간을 찾아서 가장 큰 값을 추출

 

풀이 1

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

        // https://softeer.ai/practice/6270

        /*
            *
            * 제한속도
            *
            *
            * 제한속도
            * [0, 50, 50]
            * [40, 90, 40]
            * [90, 100, 30]
            *
            * 실제속도
            * [0, 60, 76]
            * [60, 78, 28]
            * [78, 100, 50]
            *
            * 수직선에 각각으니 숫자들을 나열
            * 0 50 60 78 90 100 100
            *
            * [시작, 종료] 슬라이딩 윈도우 방식으로 각 구간의 제한속도, 실제속도를 구함
            *
            * 실제속도-제한속도 > 0 이면 초과속도
            *
            *
            *
            *
         */
        int answer = 0;

        // 제한속도, 실제속도 갯수
        String[] limitRealCount = bf.readLine().split(" ");
        int limitCount = Integer.parseInt(limitRealCount[0]);
        int realCount = Integer.parseInt(limitRealCount[1]);

        int[][] limitList = new int[limitCount][3];
        int[][] realList = new int[realCount][3];

        int limitTowerLength = 0;
        int realTowerLength = 0;

        // 전체 제한, 실제 값 입력
        List<Integer> allInputs = new ArrayList<>();
        int curIdx = 0;

        // 제한속도 값 입력
        for (int i = 0; i < limitCount; i++) {
            int[] limit = new int[3];
            String[] input = bf.readLine().split(" ");
            limit[0] = limitTowerLength;
            limit[1] = limitTowerLength + Integer.parseInt(input[0]);
            limit[2] = Integer.parseInt(input[1]);
            limitTowerLength += Integer.parseInt(input[0]);
            allInputs.add(limitTowerLength);
            curIdx++;
            limitList[i] = limit;
        }
        // 실제속도 값 입력
        for (int i = 0; i < realCount; i++) {
            int[] real = new int[3];
            String[] input = bf.readLine().split(" ");
            real[0] = realTowerLength;
            real[1] = realTowerLength + Integer.parseInt(input[0]);
            real[2] = Integer.parseInt(input[1]);
            realTowerLength += Integer.parseInt(input[0]);
            for (int j  = 0; j < allInputs.size(); j++) {
                if (allInputs.get(j) > realTowerLength) {
                    allInputs.add(j, realTowerLength);
                    break;
                } else if (allInputs.get(j) == realTowerLength) {
                    break;
                }
            }
            curIdx++;
            realList[i] = real;
        }

        // 각 점들을 돌면서 실제속도 - 제한속도
        for (int i = 0; i < allInputs.size(); i++) {
            int limitTime = 0;
            int realTime = 0;
            //실제속도
            for (int j = 0; j < limitList.length; j++) {
                if (allInputs.get(i) > limitList[j][0] && allInputs.get(i) <= limitList[j][1]) {
                    limitTime = limitList[j][2];
                }
            }
            //제한속도
            for (int j = 0; j < realList.length; j++) {
                if (allInputs.get(i) > realList[j][0] && allInputs.get(i) <= realList[j][1]) {
                    realTime = realList[j][2];
                }
            }
            answer = Math.max(answer,  realTime-limitTime);
        }
        System.out.println(answer);
    }
}

 

 

성공

 

링크

https://softeer.ai/practice/6270

 

Softeer - 현대자동차그룹 SW인재확보플랫폼

 

softeer.ai

 

728x90
반응형
LIST