개발자 톡

연습문제 톡 강의실 배정

강의실 배정 문제 시간초과 관련

등록일
2021-10-19 23:18:48
조회수
660
작성자
dongwoni3

시간 복잡도 측면에서는 크게 개선할 여지가 보이지 않는데요, 

왜 TimeOut이 뜨는건지, 시간 제약사항이 적절한건지 확인 요청드립니다.


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

class Cls{
    int start;
    int end;
    public Cls(int s, int e){
        start=s;
        end=e;
    }
}
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        List schd=new ArrayList<>();
        for(int i=0;ic1.end-c2.end);
        Cls curCls=null;
        int classN=0;
        for(Cls c:schd){
            if(curCls==null) {
                curCls=c;
                classN++;
                continue;
            }else if(curCls.end<=c.start){
                curCls=c;
                classN++;
            }
        }
        System.out.println(classN);
    }
}


#강의실_배정
#java

이 카테고리의 톡 더보기