Submission #517019

# Submission time Handle Problem Language Result Execution time Memory
517019 2022-01-22T11:25:16 Z amukkalir Holiday (IOI14_holiday) C++17
47 / 100
5000 ms 2712 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 i=s;i<n;i++){
        int rem = d - cost(s,i);
        if(rem <= 0) break;

        sum += attraction[i];
        pq.push(attraction[i]); 
        while(pq.size() > rem) {
            sum -= pq.top(); 
            pq.pop(); 
        }

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

        ll z = sum; 
        for(int j=s-1; j>=0; j--) {
            rem = d - cost(j, i); 
            if(rem <= 0) break;
            z += attraction[j]; 
            q.push(attraction[j]); 
            while(q.size() > rem) {
                z -= q.top(); 
                q.pop(); 
            }
            ans = max(ans, z); 
        }

        ans = max(ans, sum); 
    }

    return ans; 
}

/*

*/

Compilation message

holiday.cpp: In function 'long long int findMaxAttraction(int, int, int, int*)':
holiday.cpp:44:25: 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]
   44 |         while(pq.size() > rem) {
      |               ~~~~~~~~~~^~~~~
holiday.cpp:58:28: 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]
   58 |             while(q.size() > rem) {
      |                   ~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 0 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1322 ms 2636 KB Output is correct
2 Correct 1388 ms 2652 KB Output is correct
3 Correct 1493 ms 2636 KB Output is correct
4 Correct 1352 ms 2624 KB Output is correct
5 Correct 991 ms 1840 KB Output is correct
6 Correct 101 ms 1220 KB Output is correct
7 Correct 297 ms 1564 KB Output is correct
8 Correct 368 ms 1468 KB Output is correct
9 Correct 65 ms 1096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 159 ms 864 KB Output is correct
5 Correct 69 ms 752 KB Output is correct
6 Correct 3 ms 716 KB Output is correct
7 Correct 8 ms 720 KB Output is correct
8 Correct 9 ms 672 KB Output is correct
9 Correct 8 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1820 KB Output is correct
2 Correct 1332 ms 2712 KB Output is correct
3 Correct 4768 ms 956 KB Output is correct
4 Correct 59 ms 716 KB Output is correct
5 Correct 7 ms 728 KB Output is correct
6 Correct 9 ms 720 KB Output is correct
7 Correct 9 ms 716 KB Output is correct
8 Execution timed out 5030 ms 2172 KB Time limit exceeded
9 Halted 0 ms 0 KB -