Submission #893403

#TimeUsernameProblemLanguageResultExecution timeMemory
893403vjudge1Event Hopping 2 (JOI21_event2)C++17
0 / 100
3092 ms14764 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' #define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector <int> L(n), R(n); for ( int i = 0; i < n; i++ ){ cin >> L[i] >> R[i]; } { // compression vector <int> p_; for ( int i = 0; i < n; i++ ){ p_.pb(L[i]); p_.pb(R[i]); } sort(all(p_)); p_.resize(unique(all(p_)) - p_.begin()); auto get = [&](int x){ return lower_bound(all(p_), x) - p_.begin() + 1; }; for ( int i = 0; i < n; i++ ){ L[i] = get(L[i]); R[i] = get(R[i]); } } int m = n * 2; vector <vector<int>> qu(m + 1); for ( int i = 0; i < n; i++ ){ qu[L[i]].pb(R[i]); } vector <int> dp(m + 2); for ( int i = m; i > 0; i-- ){ dp[i] = dp[i + 1]; for ( auto &j: qu[i] ){ chmax(dp[i], dp[j] + 1); } } if ( dp[1] < k ){ return cout << "-1\n", 0; } vector <int> ans; int lst = -1; for ( int t = 1; t <= k; t++ ){ int j = -1; for ( int i = 0; i < n; i++ ){ if ( lst > L[i] ){ continue; } if ( dp[R[i]] >= k - t ){ j = i; break; } } assert(j != -1); ans.pb(j); lst = R[j]; } sort(all(ans)); for ( auto &x: ans ){ cout << x + 1 << ln; } cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...