# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1075385 | mindiyak | Holiday (IOI14_holiday) | C++14 | 5009 ms | 2748 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include"holiday.h"
#include <vector>
#include <set>
#include <iostream>
#include <queue>
using namespace std;
#define ll long long
ll ans = 0;
long long int findMaxAttraction(int n, int start, int d, int attraction[]) {
if(n<=20){
for(int k=1;k<(1<<n);k++){
int len = 32 - (__builtin_clz(k) + __builtin_ctz(k)) - 1;
int a = __builtin_ctz(k);
int b = 31 - __builtin_clz(k);
int cost = __builtin_popcount(k) + len + min(abs(a - start), abs(b - start));
if(cost > d)continue;
ll val = 0;
for(int i=0;i<n;i++){
if(((1<<i)&k)>0){
val += attraction[i];
}
}
ans = max(ans,val);
}
return ans;
}
if(start == 0){
priority_queue<ll> pq;
ll ans = 0;
ll cur = 0;
for(int i = 0;i<min(n,d);i++){
pq.push(-attraction[i]);
cur += attraction[i];
while(i+pq.size() > d){
cur += pq.top();pq.pop();
}
ans = max(ans,cur);
}
return ans;
}
// cerr << "started" << endl;
ll ans = 0;
for(int s=0;s<n;s++){
priority_queue<ll> pq;
ll cur = 0;
for(int i = s;i<n;i++){
int dis = (i-s) + min(abs(start-s),abs(start-i));
// cerr << i << " " << s << " " << dis << endl;
if(dis >= d)break;;
pq.push(-attraction[i]);
cur += attraction[i];
while(dis+pq.size() > d){
cur += pq.top();pq.pop();
}
ans = max(ans,cur);
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |