# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
294498 | FlashGamezzz | 사다리꼴 (balkan11_trapezoid) | C++17 | 152 ms | 11740 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
struct trap {
long a, b, c, d, i;
trap(long i1, long i2, long i3, long i4){
a = i1; b = i2; c = i3; d = i4; i = 0;
}
};
struct comp1 {
bool operator()(trap t1, trap t2){
return t1.a > t2.a;
}
};
struct comp2 {
bool operator()(trap t1, trap t2){
return t1.b > t2.b;
}
};
long n, dp[100000]; //dp[i] stores longest sequence ending in trapezoid i
priority_queue<trap, vector<trap>, comp1> pqa; // for sorting the values by a initially
priority_queue<trap, vector<trap>, comp2> pqb; // sorts trapezoids by b
map<long, long> mp; //map(i, j) j = longest sequence of trapezoids with lower right distance i
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (long i = 0; i < n; i++){
long i1, i2, i3, i4;
cin >> i1 >> i2 >> i3 >> i4;
pqa.push(trap(i1, i2, i3, i4));
}
mp.insert(make_pair(-1, 0));
long a1 = 0;
for (int i = 0; i < n; i++){
trap curr = pqa.top(); pqa.pop();
map<long, long>::iterator temp;
while (pqb.size() > 0 && pqb.top().b < curr.a){ //while the b values in our priority queue are less than our current a
temp = mp.lower_bound(pqb.top().d); temp--; //find lowest value in map that's smaller than our current
mp.insert(make_pair(pqb.top().d, max(dp[pqb.top().i], temp->second))); //map values
pqb.pop();
}
curr.i = i; //set i so that we can find the dp value associated with this trapezoid
pqb.push(curr);
temp = mp.lower_bound(curr.c); temp--; //find longest sequence of trapezoids with lower right distance i less than curr.c
dp[i] = temp->second + 1;
a1 = max(a1, dp[i]);
}
cout << a1 << " " << 0 << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |