Submission #411161

# Submission time Handle Problem Language Result Execution time Memory
411161 2021-05-24T12:37:12 Z 반딧불(#7588) JOI15_keys (JOI15_keys) C++14
10 / 100
39 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m, k;
int s[22], e[22];
bool chk[22];
int ans;
vector<pair<int, int> > vec;

int main(){
    scanf("%d %d %d", &n, &m, &k);
    for(int i=0; i<n; i++){
        scanf("%d %d", &s[i], &e[i]);
        vec.push_back(make_pair(s[i], i));
        vec.push_back(make_pair(e[i], i));
    }
    sort(vec.begin(), vec.end());

    for(int d=0; d<(1<<n); d++){
        if(__builtin_popcount(d) != k) continue;
        int sum = 0, openPrev = 0;
        bool open = 0;
        for(int i=0; i<(int)vec.size(); i++){
            auto p = vec[i];
            int x = p.second, t = p.first;
            if(!open) sum += (t - openPrev);
            openPrev = t;
            if(!chk[x] && !((d>>x)&1)) open = true;
            else if(i < (int)vec.size()-1 && chk[vec[i+1].second] && !((d>>vec[i+1].second)&1)) open = true;
            else open = false;

            chk[x] = !chk[x];
        }
        if(!open) sum += m - openPrev;
        ans = max(ans, sum);
    }
    printf("%d", ans);
}

Compilation message

keys.cpp: In function 'int main()':
keys.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
keys.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%d %d", &s[i], &e[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 36 ms 268 KB Output is correct
3 Correct 4 ms 204 KB Output is correct
4 Correct 26 ms 288 KB Output is correct
5 Correct 4 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 39 ms 204 KB Output is correct
8 Correct 13 ms 204 KB Output is correct
9 Correct 4 ms 204 KB Output is correct
10 Correct 18 ms 288 KB Output is correct
11 Correct 36 ms 272 KB Output is correct
12 Correct 6 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 36 ms 268 KB Output is correct
3 Correct 4 ms 204 KB Output is correct
4 Correct 26 ms 288 KB Output is correct
5 Correct 4 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 39 ms 204 KB Output is correct
8 Correct 13 ms 204 KB Output is correct
9 Correct 4 ms 204 KB Output is correct
10 Correct 18 ms 288 KB Output is correct
11 Correct 36 ms 272 KB Output is correct
12 Correct 6 ms 204 KB Output is correct
13 Incorrect 1 ms 204 KB Output isn't correct
14 Halted 0 ms 0 KB -