Submission #659814

# Submission time Handle Problem Language Result Execution time Memory
659814 2022-11-19T10:05:19 Z Tenis0206 Event Hopping 2 (JOI21_event2) C++11
0 / 100
3000 ms 2436 KB
#include <bits/stdc++.h>

using namespace std;

struct event
{
    int l,r;
};

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);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].l>>v[i].r;
        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)
    {
        for(int j=poz+1;j<=n;j++)
        {
            if(v[j].l >= v[poz].r && dp[j]>=k)
            {
                poz = j;
                break;
            }
        }
        rez.push_back(poz);
        --k;
    }
    for(auto it : rez)
    {
        cout<<it<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 3049 ms 2436 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 3049 ms 2436 KB Time limit exceeded
5 Halted 0 ms 0 KB -