Submission #517002

# Submission time Handle Problem Language Result Execution time Memory
517002 2022-01-22T10:57:30 Z amukkalir Holiday (IOI14_holiday) C++17
23 / 100
5000 ms 2084 KB
#include <bits/stdc++.h>
#include"holiday.h"
using namespace std; 
typedef long long ll;

const int nax = 20; 
int n; 

int s, d; 

int cost (int l, int r) {
    return (r-l) + min(abs(s-l), abs(r-s)); 
}

bool ok (int mask) {
    int l=n, r=0; 
    for(int i=0; (1<<i)<=mask; i++) {
        if(mask & (1<<i)) {
            l = min(l, i); 
            r = max(r, i); 
        }
    }

    int travel = (r-l) + min(abs(s-l), abs(r-s)); 
    return travel + __builtin_popcount(mask) <= d; 
}

long long int findMaxAttraction(int N, int S, int D, int attraction[]) {
    n = N; 
    s = S; d = D; 
    ll ans = 0; 

    priority_queue<ll, vector<ll>, greater<ll>> pq;

    ll sum = 0; 
    for(int l=0; l<=s; l++) {
        while(!pq.empty()) pq.pop(); 
        for(int i=s;i<n;i++){
            int rem = d - cost(l,i);
            if(d <= 0) break;
            sum += attraction[i];
            pq.push(attraction[i]); 
            while(pq.size() > rem) {
                sum -= pq.top(); 
                pq.pop(); 
            }
            ans = max(ans, sum); 
        }
    }

    return ans; 
}

/*
k terbesar O(N)

sliding window + binser
deque
rangenya difix 
*/

Compilation message

holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:43:29: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |             while(pq.size() > rem) {
      |                   ~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2084 KB Output is correct
2 Correct 7 ms 1960 KB Output is correct
3 Correct 12 ms 1928 KB Output is correct
4 Correct 10 ms 1988 KB Output is correct
5 Correct 14 ms 1564 KB Output is correct
6 Correct 3 ms 1100 KB Output is correct
7 Correct 7 ms 1312 KB Output is correct
8 Correct 10 ms 1480 KB Output is correct
9 Correct 3 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 836 KB Output is correct
2 Correct 13 ms 1828 KB Output is correct
3 Execution timed out 5085 ms 1228 KB Time limit exceeded
4 Halted 0 ms 0 KB -