Submission #1052780

#TimeUsernameProblemLanguageResultExecution timeMemory
1052780ItamarMeetings (IOI18_meetings)C++14
19 / 100
144 ms201508 KiB
using namespace std;
#include <vector>
#define ll long long
#define vll vector<ll>

vll h;
const int siz = 5002;
int maxi[siz][siz];
ll q(int a,int b){
  if(a>b)return 0;
  int in = maxi[a][b];
  return min((b-in+1)*h[in]+q(a,in-1), (in-a+1)*h[in]+q(in+1,b));
}
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
                                     std::vector<int> R) {
  for(int hi :H)h.push_back(hi);
  int Q = L.size();
  std::vector<ll> ans(Q);
  int N= H.size();
  for(int i = 0; i < N; i++){
    int m = i;
    for(int j = i; j < N; j++){
      if(H[j]>H[m])m=j;
      maxi[i][j]=m;
    }
  }
  for (int j = 0; j < Q; ++j) {
    ans[j] = q(L[j],R[j]);
  }

  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...