Submission #1106410

#TimeUsernameProblemLanguageResultExecution timeMemory
1106410LucaLucaMPeru (RMI20_peru)C++17
0 / 100
1 ms336 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cassert> #include <queue> #warning That's not the baby, that's my baby #define debug(x) #x << " = " << x << '\n' using ll = long long; const ll INF = 1e18; const int mod = 1e9 + 7; int toHash(std::vector<ll> x) { int ret = 0; for (int i = 0; i < (int) x.size(); i++) { x[i] %= mod; ret = ((ll) ret * 23 + x[i]) % mod; } return ret; } struct Info { int index, maxi; ll cost; }; int solve(int n, int k, int *A) { std::vector<ll> dp(n + 1, INF); std::vector<int> a(n + 1, 0); for (int i = 0; i < n; i++) { a[i + 1] = A[i]; } dp[0] = 0; std::deque<Info> deq; deq.push_back({0, 0, 0}); for (int i = 1; i <= n; i++) { int ptr = (int) deq.size() - 1; while (ptr >= 0 && deq[ptr].maxi < a[i]) { deq[ptr].cost += a[i] - deq[ptr].maxi; deq[ptr].maxi = a[i]; ptr--; } dp[i] = deq.front().cost; while (!deq.empty() && deq.front().index <= i - k + 1) { deq.pop_front(); } Info me; me.index = i; me.cost = dp[i - 1] + a[i]; me.maxi = a[i]; while (!deq.empty() && me.cost < deq.back().cost) { deq.pop_back(); } deq.push_back(me); } dp.erase(dp.begin()); // std::cout << "\n\nDP: "; // for (int i = 0; i < n; i++) { // std::cout << dp[i] << ' '; // } return toHash(dp); } #ifdef LOCAL int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n, k; std::cin >> n >> k; int *a = new int[n]; for (int i = 0; i < n; i++) { std::cin >> a[i]; } std::cout << solve(n, k, a); return 0; } #endif

Compilation message (stderr)

peru.cpp:6:2: warning: #warning That's not the baby, that's my baby [-Wcpp]
    6 | #warning That's not the baby, that's my baby
      |  ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...