20250811 baekjoon

This commit is contained in:
songyc macbook 2025-08-11 23:55:49 +09:00
parent a1db4a6823
commit 5a6752ef70
2 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,43 @@
import java.util.*;
class Meeting_Hour implements Comparable<Meeting_Hour>{
public int start;
public int end;
Meeting_Hour(int start, int end){
this.start = start;
this.end = end;
}
public int compareTo(Meeting_Hour another){
if(this.end == another.end) return this.start - another.start;
return this.end - another.end;
}
}
public class _1931 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Meeting_Hour> meetingList = new ArrayList<>();
int N = sc.nextInt();
for(int i=0; i<N; i++){
meetingList.add(new Meeting_Hour(sc.nextInt(),sc.nextInt()));
}
sc.close();
Collections.sort(meetingList);
// meetingList.sort((a,b)->{
// if(a.end == b.end) return a.start - b.start;
// return a.end - b.end;
// });
int currentEnd = meetingList.get(0).end;
int result = 1;
for(int i=1; i<N; i++){
if(currentEnd<=meetingList.get(i).start){
currentEnd = meetingList.get(i).end;
result++;
}
}
System.out.println(result);
}
}

View File

@ -0,0 +1,48 @@
import sys
from collections import deque
input = sys.stdin.readline
N, M, H = map(int, input().split())
visited = [[[-1]*N for _ in range(M)] for _ in range(H)]
emptyCount = 0
visitCount = 0
q = deque()
tomato = []
for z in range(H):
tomato.append([])
for y in range(M):
row = list(map(int, input().split()))
tomato[z].append(row)
for x in range(N):
if row[x] == 1 :
q.append((z,y,x))
visited[z][y][x] = 0
visitCount += 1
elif row[x] == -1 :
emptyCount += 1
dx = [1,-1,0,0,0,0]
dy = [0,0,1,-1,0,0]
dz = [0,0,0,0,1,-1]
dayMax = 0
while len(q) :
cz, cy, cx = q.popleft()
for i in range(6):
nz, ny, nx = cz + dz[i], cy + dy[i], cx + dx[i]
if 0<=nz<H and 0<=ny<M and 0<=nx<N and visited[nz][ny][nx] == -1 and tomato[nz][ny][nx] == 0:
q.append((nz,ny,nx))
visitCount += 1
visited[nz][ny][nx] = visited[cz][cy][cx] + 1
if visited[nz][ny][nx] > dayMax :
dayMax = visited[nz][ny][nx]
if N*M*H == visitCount + emptyCount :
print(dayMax)
else :
print(-1)