Submission #505041

# Submission time Handle Problem Language Result Execution time Memory
505041 2022-01-10T12:29:15 Z Jarif_Rahman JOI15_keys (JOI15_keys) C++17
10 / 100
1000 ms 336 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int inf = 1e9+1;

int mn = inf;
int n, m, k;

vector<pair<int, int>> events;
vector<pair<int, int>> pp;
vector<pair<int, int>> ss;

void bf(int in){
    if(in == n){
        if(ss.size() != k) return;
        set<int> s;
        for(int i = 0; i < k; i++) s.insert(ss[i].f), s.insert(ss[i].sc);
        int cur = 0;
        for(int i: s) cur+=events[i+1].f-events[i].f;
        mn = min(mn, cur);
        return;
    }
    ss.pb(pp[in]);
    bf(in+1);
    ss.pop_back();
    bf(in+1);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> k;
    k = n-k;

    for(int i = 0; i < n; i++){
        int x, y; cin >> x >> y; 
        events.pb({x, i+1});
        events.pb({y, -i-1});
    }

    sort(events.begin(), events.end());
    pp.resize(n);
    for(int i = 0; i < 2*n; i++){
        if(events[i].sc > 0) pp[events[i].sc-1].f = i;
        else pp[-events[i].sc-1].sc = i-1;
    }

    int ans = m;

    bf(0);

    ans-=mn;

    cout << ans << "\n";
}

Compilation message

keys.cpp: In function 'void bf(int)':
keys.cpp:19:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |         if(ss.size() != k) return;
      |            ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 208 KB Output is correct
2 Correct 195 ms 312 KB Output is correct
3 Correct 9 ms 208 KB Output is correct
4 Correct 103 ms 240 KB Output is correct
5 Correct 7 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 153 ms 300 KB Output is correct
8 Correct 39 ms 208 KB Output is correct
9 Correct 8 ms 208 KB Output is correct
10 Correct 71 ms 208 KB Output is correct
11 Correct 95 ms 208 KB Output is correct
12 Correct 7 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 208 KB Output is correct
2 Correct 195 ms 312 KB Output is correct
3 Correct 9 ms 208 KB Output is correct
4 Correct 103 ms 240 KB Output is correct
5 Correct 7 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 153 ms 300 KB Output is correct
8 Correct 39 ms 208 KB Output is correct
9 Correct 8 ms 208 KB Output is correct
10 Correct 71 ms 208 KB Output is correct
11 Correct 95 ms 208 KB Output is correct
12 Correct 7 ms 312 KB Output is correct
13 Execution timed out 1084 ms 336 KB Time limit exceeded
14 Halted 0 ms 0 KB -