-
Notifications
You must be signed in to change notification settings - Fork 1
20-Fnhid #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λκ°κ±°λ λΉμ·λΉμ·ν λ¬Έμ λ€μ λͺλ² νμ΄λ΄μ κΈλ°© ν΄κ²°ν μ μμμ΅λλ€.
μ²μμ΄λΌλ©΄ μ λ μκ°μ΄ κ½€ κ±Έλ Έμ κ² κ°λ€μ..
λ¬Έμ μμ κ°μ μκ°μ λ²μλ₯Ό 0μ΄μ 10μ΅ μ΄νμ μ μλ‘ μ£Όμκ³ ,
intκ° μ½ +20μ΅ ~ -20μ΅ ν¬κΈ°μ μ μμλ£νμ λ€λ£° μ μμΌλ―λ‘ κ΅³μ΄ long longμ μ¬μ©νμ§ μκ³ λ ν΄κ²°ν μ μμ΅λλ€.
κ°μλ€μ μμμκ°κ³Ό μ’
λ£μκ°μ λΉκ΅νλ λ°λ³΅λ¬Έμ C++17λΆν° μ§μνλ ꡬ쑰μ λ°μΈλ©(Structured binding) μ μ¬μ©νμ¬ κ΅¬μ‘°μ²΄ μμ΄ ν΄κ²°νμμ΅λλ€.
μ λ λ°°μ΄μ§ μΌλ§ μλμ΄μ(μ¬κΈ°μ λ°°μ μ΅λλ€!!) μκ°λ λ λ§λ€ μ¨λ¨Ήμ΄λ³΄λμ€μ
λλ€ γ
γ
μ 체 λ‘μ§μ λμΌν κ² κ°λ€μ©.
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
vector<pair<int, int>> lectures;
for(int i = 0; i < N; ++i) {
int lectureNumber, start, end;
cin >> lectureNumber >> start >> end;
lectures.push_back({start, end});
}
sort(lectures.begin(), lectures.end());
priority_queue<int, vector<int>, greater<int>> pq;
int answer = 0;
for(auto [start, end] : lectures) {
while(!pq.empty() && pq.top() <= start) {
pq.pop();
}
pq.push(end);
answer = max(answer, (int)pq.size());
}
cout << answer << '\n';
return 0;
}| int max(int a, int b) | ||
| { | ||
| return a > b ? a : b; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<algorithm> λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©ν κ²½μ°,
λ μΈμλ₯Ό λΉκ΅νμ¬ μ΅λκ°κ³Ό μ΅μκ°μ λ°ννλ max() μ min() ν¨μλ₯Ό μ 곡ν΄μ£ΌκΈ°λλ¬Έμ
컀μ€ν
ν¨μ μ μΈ μμ΄ μ¬μ©ν μ μμ΅λλ€. νΈλ¦¬ν΄μ© γ
γ
μ°Έκ³ λ‘ max()ν¨μμ λ΄λΆ μ½λ κ΅¬μ‘°κ° μ νλμ΄ μ μΈνμ 컀μ€ν
ν¨μμ λμΌν©λλ€ γ
γ
γ
|
μ€νΈ ꡬ쑰μ λ°μΈλ©μ΄λΌλ λ¬Έλ²μ΄ μκ΅°μ..!!! μ μ©ν κ² κ°λ€μ μ λ λ€μμ μ¨ λ³΄λλ‘ νκ² μ΅λλ€. + μμ¦ μ μ μ΄ μμ΄μ.. int λ²μκ° ν·κ°λ¦¬λ μ§κ²½μ μ΄λ₯΄λ λ€μ..γ γ γ γ μμ νκ² μ΅λλ€π« |
|
μ°μ μμ νλ₯Ό μ¬μ©νλ λ€λ₯Έ λ¬Έμ λ₯Ό νμ΄λ³Έ μ μμ΄μ, κ·Έ μ½λλ₯Ό μ΄ν΄λ³΄λ©° κΈ°μ΅μ λμ§μ΄λ³΄λ©° μ΄ λ¬Έμ λ₯Ό λΉ λ₯΄κ² ν΄κ²°ν΄λ΄€μ΅λλ€. μμ μκ°μ κΈ°μ€μΌλ‘ μ λ ¬ ν import sys, heapq
input = sys.stdin.readline
n = int(input())
lecture = []
for _ in range(n):
a,b,c = map(int,input().split())
lecture.append((a,b,c))
lecture.sort(key=lambda x:x[1])
heap=[]
for _, start, end in lecture:
if heap and heap[0]<=start:
heapq.heappop(heap)
heapq.heappush(heap, end)
print(len(heap)) |
hadongun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμ€μγ
μ΄λμ λ³Έ λ¬Έμ κ°μλ°.. κΈ°μ΅μ΄ μ μλμ μ΄κ²μ κ² μ°Έκ³ νμ΅λλ€..!
μ°μ μμ νλ₯Ό λ°°μ μ§λ§ μ΄λ°μμΌλ‘ μ¬μ©ν μ μλ€λκ² μ°Έ μ κΈ°νλ€μ
μ¬λ¬ λΆλΆλ€μ μ νλ©΄μ μ’ μ΅μν΄μ Έμ νμ© λ₯λ ₯μ ν€μ보λλ‘ νκ² μ΅λλ€!~
import sys
import heapq
input = sys.stdin.readline
n = int(input())
lecture = []
for _ in range(n):
x, y, z = map(int, input().split())
lecture.append((x, y, z))
lecture.sort(key = lambda x: x[1])
heap = []
time = 0
for lec in lecture:
start = lec[1]
end = lec[2]
if heap and heap[0] <= start:
heapq.heappop(heap)
heapq.heappush(heap, end)
print(len(heap))
π λ¬Έμ λ§ν¬
κ°μμ€
βοΈ μμλ μκ°
ν λ§ ν΄ λ³΄μμ§λ§ μ΄λ° λ¬Έμ κ° μ΅μνμ§ μμμ κ·Έλ°μ§
μμ΄λμ΄λ₯Ό λ μ¬λ¦¬κΈ°κ° μ½μ§ μλ€μ,,
40λΆ μ―€μ ꡬκΈλ§μΌλ‘ ννΈλ₯Ό μ»μ΄ μ΄ 1μκ° μμνμ¬ ν΄κ²°νμ΅λλ€.
λ¬Έμ μμ΄λμ΄λ₯Ό μλͺ» μκ°ν΄μ μ½μ§μ μ€λ νμ΅λλ€
β¨ μλ μ½λ
κ°μμ κ°μκ° μ£Όμ΄μ§κ³ ,
κ° κ°μμ μΈλ±μ€, μμ μκ°, μ’ λ£ μκ°μ΄ μ£Όμ΄μ§λλ€.
μ΄ λ κ°μλ₯Ό κ²ΉμΉμ§ μκ² κ°μμ€μ λ°°μ νλ €λ©΄ μ΅μ λͺ κ°μ κ°μμ€μ λ°°μ ν΄μΌ νλμ§ μμλ΄λ λ¬Έμ μ λλ€.
λ¨Όμ κ°μλ₯Ό μμ μκ°μ΄ λΉ λ₯Έ μμΌλ‘ μ λ ¬ν©λλ€.

μ°μ μμ ν
μ λ ¬λ μμλλ‘ κ°μλ₯Ό μ°μ μμ νμ μ½μ νλλ°, (μ½μ ν κ°μλ₯Ό L, μ°μ μμ νμ topμ μλ κ°μλ₯Ό TλΌ νκ² μ΅λλ€)
μ΄ λ λ§μ½ Tμ μ’ λ£ μκ°μ΄ Lμ μμ μκ°κ³Ό κ°κ±°λ μμ μμΌλ©΄, κ°μ κ°μμ€μ μ¬μ©ν μ μμΌλ―λ‘ topμ popν΄ μ€λλ€.
μ΄ν Lμ μ’ λ£ μκ°μ μλ‘ pushν©λλ€.
μ΄λ₯Ό λ°λ³΅νλ©΄, κ°μκ° λ€μ΄μ¬ λ λ§λ€ νμν κ°μμ€μ μλ₯Ό μ μ μμ΅λλ€.
λ°λ‘ μ°μ μμ νμ μμμ κ°μμ λλ€.
λ°λΌμ, μ°μ μμ νμ μμμ κ°μμ μ΅λκ°μ ꡬνλ©΄ λ¬Έμ λ₯Ό ν΄κ²°ν μ μμ΅λλ€.
π μλ‘κ² μκ²λ λ΄μ©
μ°μ μμ νκ°μ μλ£κ΅¬μ‘°λ λ°°μ λλ°λ μμ§ νμ©νκΈ° μ΄λ ΅λ€μ.. λ λ§μ΄ νμ΄λ³΄λ©΄μ μ΅μν΄μ Έ λ³΄κ² μ΅λλ€.