이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
typedef long long ll;
using namespace std;
int n, x;
map<int, int> dp[2]; // dp[pridali sme uz x?][koniec] = dlzka
void update(int l, int len, int end)
{
if (!dp[l].count(end)) dp[l][end] = len;
else dp[l][end] = max(dp[l][end], len);
auto it = dp[l].find(end);
if (it != dp[l].begin() && prev(it)->second >= len)
{
dp[l].erase(it);
return;
}
while (next(it) != dp[l].end() && next(it)->second <= len)
{
dp[l].erase(next(it));
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> x;
vector<int> t(n);
for (int i = 0; i < n; i++) cin >> t[i];
dp[0][0] = dp[1][0] = 0;
for (int i = 0; i < n; i++)
{
// pouzijeme moznost zvysit sufix
int len = prev(dp[0].lower_bound(t[i] + x))->second + 1;
update(1, len, t[i]);
for (int j = 0; j < 2; j++)
{
auto it = prev(dp[j].lower_bound(t[i]));
update(j, it->second + 1, t[i]);
}
cout << i << ", " << t[i] << ": "
<< prev(dp[0].end())->second << " " << prev(dp[1].end())->second << endl;
}
cout << prev(dp[1].end())->second << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |