Submission #659816

#TimeUsernameProblemLanguageResultExecution timeMemory
659816Tenis0206Event Hopping 2 (JOI21_event2)C++11
0 / 100
3052 ms2792 KiB
#include <bits/stdc++.h> //#define home using namespace std; struct event { int l,r,poz; }; int n,k; event v[100005]; int dp[100005]; vector<int> a; int get_val(int val) { int st = 1; int dr = a.size(); int poz = 0; while(st<=dr) { int mij = (st + dr) >> 1; if(a[mij-1]<=val) { poz = mij; st = mij + 1; } else { dr = mij - 1; } } return poz; } int main() { ios::sync_with_stdio(false); cin.tie(0); #ifdef home freopen("nr.in","r",stdin); freopen("nr.out","w",stdout); #endif // home cin>>n>>k; for(int i=1;i<=n;i++) { cin>>v[i].l>>v[i].r; v[i].poz = i; a.push_back(v[i].l); a.push_back(v[i].r); } sort(a.begin(),a.end()); /* for(int i=1;i<=n;i++) { v[i].l = get_val(v[i].l); v[i].r = get_val(v[i].r); } */ sort(v+1,v+n+1,[](event a, event b){return a.l<b.l;}); int poz = 0; for(int i=n;i>=1;i--) { dp[i] = 1; for(int j=i+1;j<=n;j++) { if(v[j].l >= v[i].r) { dp[i] = max(dp[i], 1 + dp[j]); } } if(dp[i] >= k) { poz = i; } } if(!poz) { cout<<-1<<'\n'; return 0; } --k; vector<int> rez; rez.push_back(poz); while(k) { int new_poz = 0; for(int j=poz+1;j<=n;j++) { if(v[j].l >= v[poz].r && dp[j]>=k) { if(v[j].poz < v[new_poz].poz || !new_poz) { new_poz = j; } } } poz = new_poz; rez.push_back(poz); --k; } sort(rez.begin(),rez.end()); for(auto it : rez) { cout<<it<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...