Submission #930279

#TimeUsernameProblemLanguageResultExecution timeMemory
930279boris_mihovEvent Hopping 2 (JOI21_event2)C++17
1 / 100
3010 ms3264 KiB
#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 intersecting(int x, int y) { return std::max(l[x], l[y]) < std::min(r[x], r[y]); } bool canAdd(int idx) { int cntLeft = sol.size(); for (const int &i : ans) { if (intersecting(idx, i)) { return false; } } for (const int &i : sol) { if (intersecting(idx, i)) { 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 (!intersecting(idx, i)) { 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] || (r[x] == r[y] && l[x] > l[y]); }); for (int i = 1 ; i <= n ; ++i) { if (sol.empty() || !intersecting(sol.back(), perm[i])) { sol.push_back(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); } } assert(ans.size() == k); 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)

event2.cpp: In function 'bool canAdd(int)':
event2.cpp:47:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |   return cntLeft + ans.size() + 1 >= k;
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
event2.cpp: In function 'void removeIntersecting(int)':
event2.cpp:53:7: warning: unused variable 'cntLeft' [-Wunused-variable]
   53 |   int cntLeft = sol.size();
      |       ^~~~~~~
event2.cpp: In function 'void solve()':
event2.cpp:81:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |   if (sol.size() < k)
      |       ~~~~~~~~~~~^~~
event2.cpp:87:41: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   87 |   for (int i = 1 ; i <= n && ans.size() < k ; ++i)
      |                              ~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/cassert:44,
                 from event2.cpp:4:
event2.cpp:96:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   96 |   assert(ans.size() == k);
      |          ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...