9월 26일(금)
백준 - 3758번: KCPC
https://www.acmicpc.net/problem/3758
풀이출처 -> https://seyeon-hello.tistory.com/42
import sys
input=sys.stdin.readline
T=int(input())
for _ in range(T):
n,k,t,m=map(int,input().split())
board=[[0]*k for _ in range(n)]
count=[0]*n #제출횟수
time=[0]*n #제출시간
for ts in range(m):
i,j,s=map(int,input().split())
board[i-1][j-1]=max(board[i-1][j-1],s)
time[i-1]=ts
count[i-1]+=1
new=[]
for idx in range(len(board)):
new.append([sum(board[idx]),count[idx],time[idx],idx])
new.sort(key=lambda x:(-x[0],x[1],x[2])) #규칙대로정렬
for idx in range(len(new)):
if new[idx][3]==t-1:
print(idx+1)
break
백준 - 20310번: 타노스
백준 - 19637번: IF문 좀 대신 써줘
https://www.acmicpc.net/problem/19637
1) 이분탐색 -> 직접 구현
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
title = [input().split() for _ in range(n)]
title.sort(key=lambda x: int(x[1]))
characters = [int(input().strip()) for _ in range(m)]
for ch in characters:
left = 0
right = len(title)
result = 0
while left <= right:
mid = (left+right)//2
if int(title[mid][1]) >= ch:
right = mid - 1
result = mid
else:
left = mid + 1
print(title[result][0])
2) 이분탐색 -> bisect 활용
https://daradarav.tistory.com/119
import sys
input = sys.stdin.readline
from bisect import bisect_left
n, m = map(int, input().split())
titles = []
nums = []
for _ in range(n):
a, b = input().split()
titles.append(a)
nums.append(int(b))
for _ in range(m):
print(titles[bisect_left(nums, int(input()))])'백준(Python > 25년 9월' 카테고리의 다른 글
| [Python] 백준 - Queue 문제 풀이 (0) | 2025.10.01 |
|---|---|
| [Python] 백준 - Stack 문제 풀이 (0) | 2025.09.29 |
| [Python] 백준 - 19941번: 햄버거 분배 (0) | 2025.09.24 |
| [Python] 백준 - 2512번: 예산 (0) | 2025.09.22 |
| [Python] 백준 - 2164번: 카드2 (0) | 2025.09.19 |
댓글