회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
17퍼에서 시간 좀 걸리다가 20퍼에서 시간 초과 나요..
1931번 - 회의실 배정
aa2002dcks
2년 전
0
도와주세요..
이유도 알려주시면 감사하겠습니다..
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.LinkedList; public class Main { static int highsu(boolean time[],int times[][],int start,int high,int now,int meme[]) { if(meme[now]!=0) return meme[now]; for(int i=start;i<times.length;i++) { int check=0; if(now>times[i][0]) continue; for(int k=times[i][0];k<times[i][1];k++) { if(time[k]==true) { check=1; break;} } if(check==0) { for(int j=times[i][0];j<times[i][1];j++) { time[j]=true; } now=times[i][0]; high+=highsu(time,times,i+1,high,times[i][1],meme); high++; break; } } meme[now]=high; return high; } public static void main(String args[]) throws NumberFormatException, IOException { BufferedReader id = new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(id.readLine()); int i; int times[][]= new int [n][2]; int high=0; int now=0; for(i=0;i<n;i++) { String[] input=id.readLine().split(" "); times[i][0]=Integer.parseInt(input[0]); times[i][1]=Integer.parseInt(input[1]); } Arrays.sort(times, new Comparator<int[]>() { public int compare(int[] o1,int[] o2) { if(o1[1]==o2[1]) return o1[0]-o2[0]; return o1[1]-o2[1]; } }); boolean time[]=new boolean [times[n-1][1]+1]; int memo[]=new int [times[n-1][1]+1]; for(i=0;i<n;i++) { Arrays.fill(time, false); high = Math.max(highsu(time, times, i,0,now,memo), high); } System.out.print(high); } }
댓글을 작성하려면
로그인
해야 합니다.
aa2002dcks 2년 전
도와주세요..
이유도 알려주시면 감사하겠습니다..