# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
930273 | boris_mihov | Event Hopping 2 (JOI21_event2) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set>
typedef long long llong;
const int MAXN = 100000 + 10;
const int INF = 2e9;
int n, k;
int l[MAXN];
int r[MAXN];
int perm[MAXN];
std::vector <int> sol;
std::vector <int> ans;
bool canAdd(int idx)
{
int cntLeft = sol.size();
for (const int &i : ans)
{
if ((l[i] <= l[idx] && l[idx] <= r[i]) || (l[idx] <= l[i] && l[i] <= r[idx]))
{
return false;
}
}
for (const int &i : sol)
{
if ((l[i] <= l[idx] && l[idx] <= r[i]) || (l[idx] <= l[i] && l[i] <= r[idx]))
{
cntLeft--;
}
}
return cntLeft + ans.size() + 1 >= k;
}
void removeIntersecting(int idx)
{
std::vector <int> sol2;
int cntLeft = sol.size();
for (const int &i : sol)
{
if (!((l[i] <= l[idx] && l[idx] <= r[i]) || (l[idx] <= l[i] && l[i] <= r[idx])))
{
sol2.push_back(i);
}
}
sol = sol2;
}
void solve()
{
std::iota(perm + 1, perm + 1 + n, 1);
std::sort(perm + 1, perm + 1 + n, [&](int x, int y)
{
return r[x] < r[y];
});
int end = 0;
for (int i = 1 ; i <= n ; ++i)
{
if (l[perm[i]] > end)
{
sol.push_back(perm[i]);
end = r[perm[i]];
}
}
if (sol.size() < k)
{
std::cout << -1 << '\n';
return;
}
for (int i = 1 ; i <= n && ans.size() < k ; ++i)
{
if (canAdd(i))
{
ans.push_back(i);
removeIntersecting(i);
}
}
for (const int &idx : ans)
{
std::cout << idx << '\n`';
}
}
void input()
{
std::cin >> n >> k;
for (int i = 1 ; i <= n ; ++i)
{
std::cin >> l[i] >> r[i];
l[i]++;
}
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int main()
{
fastIOI();
input();
solve();
return 0;
}
Compilation message (stderr)
# | 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... |