Submission #710637

#TimeUsernameProblemLanguageResultExecution timeMemory
710637CyanmondMeetings (IOI18_meetings)C++17
19 / 100
5550 ms6004 KiB
#include "meetings.h" #include <bits/stdc++.h> using i64 = long long; constexpr i64 inf = 1ll << 50; std::vector<i64> solve(const std::vector<i64> &H) { const int N = (int)H.size(); std::vector<i64> valList(N); std::stack<std::pair<int, i64>> stk; i64 sum = 0; for (int i = 0; i < N; ++i) { // update int u = 1; while ((not stk.empty()) and (stk.top().second <= H[i])) { sum -= stk.top().second * stk.top().first; u += stk.top().first; stk.pop(); } stk.push({u, H[i]}); sum += u * H[i]; valList[i] = sum; } return valList; } std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L, std::vector<int> R) { int N = (int)H.size(), Q = (int)L.size(); std::vector<i64> answer(Q); for (int i = 0; i < Q; ++i) { std::vector<i64> h(R[i] - L[i] + 1); for (int j = L[i]; j <= R[i]; ++j) h[j - L[i]] = H[j]; const auto x = solve(h); std::reverse(h.begin(), h.end()); auto y = solve(h); std::reverse(y.begin(), y.end()); for (int j = L[i]; j <= R[i]; ++j) y[j - L[i]] -= H[j]; i64 res = inf; for (int j = 0; j < (R[i] - L[i] + 1); ++j) { res = std::min(res, x[j] + y[j]); } answer[i] = res; } return answer; }

Compilation message (stderr)

meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:29:9: warning: unused variable 'N' [-Wunused-variable]
   29 |     int N = (int)H.size(), Q = (int)L.size();
      |         ^
#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...