Submission #1062836

# Submission time Handle Problem Language Result Execution time Memory
1062836 2024-08-17T11:08:04 Z TimDee Peru (RMI20_peru) C++17
100 / 100
402 ms 72852 KB
    #include "peru.h"
    #include <bits/stdc++.h>
     
    using namespace std;
     
    const int md = 1e9 + 7;
     
    int add(int x, int y) {
      return x + y < md ? x + y : x + y - md;
    }
     
    int mul(int x, int y) {
      return x * 1LL * y % md;
    }
     
    int solve(int n, int k, int* v) {
      vector<int> ft(n);
      deque<int> dq;
      for (int i = 0; i < n; i++) {
        while (!dq.empty() && v[i] >= v[dq.back()]) {
          dq.pop_back();
        }
        while (!dq.empty() && i - dq.front() + 1 > k) {
          dq.pop_front();
        }
        dq.push_back(i);
        ft[i] = v[dq.front()];
      }
      const long long inf = (long long) 1e18;
      vector<long long> dp(n, inf);
      multiset<pair<long long, int>> st;
      vector<array<int, 3>> stk;
      for (int i = 0; i < n; i++) {
        int border = i;
        while (!stk.empty() && v[i] > stk.back()[0]) {
          border = stk.back()[1];
          st.erase({(border == 0 ? 0LL : dp[border - 1]) + stk.back()[0], border});
          stk.pop_back();
        }
        stk.push_back({v[i], border, i});
        st.emplace((border == 0 ? 0LL : dp[border - 1]) + v[i], border);
        while (!st.empty() && i - st.begin()->second + 1 > k) {
          st.erase(st.begin());
        }
        if (!st.empty()) {
          dp[i] = min(dp[i], st.begin()->first);
        }
        int j = max(0, i - k + 1);
        dp[i] = min(dp[i], (j == 0 ? 0LL : dp[j - 1]) + ft[i]);
      }
      int res = 0;
      int pw = 1;
      for (int i = n - 1; i >= 0; i--) {
        dp[i] %= md;
        res = add(res, mul(pw, dp[i]));
        pw = mul(pw, 23);
      }
      return res;
    }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 524 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 524 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 51 ms 11100 KB Output is correct
16 Correct 52 ms 11100 KB Output is correct
17 Correct 54 ms 11308 KB Output is correct
18 Correct 40 ms 10736 KB Output is correct
19 Correct 38 ms 10920 KB Output is correct
20 Correct 37 ms 10684 KB Output is correct
21 Correct 53 ms 11112 KB Output is correct
22 Correct 60 ms 11604 KB Output is correct
23 Correct 55 ms 11628 KB Output is correct
24 Correct 51 ms 11332 KB Output is correct
25 Correct 54 ms 11784 KB Output is correct
26 Correct 52 ms 11088 KB Output is correct
27 Correct 54 ms 11136 KB Output is correct
28 Correct 54 ms 11460 KB Output is correct
29 Correct 52 ms 11488 KB Output is correct
30 Correct 52 ms 11092 KB Output is correct
31 Correct 48 ms 11088 KB Output is correct
32 Correct 56 ms 11356 KB Output is correct
33 Correct 50 ms 11092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 11100 KB Output is correct
2 Correct 52 ms 11100 KB Output is correct
3 Correct 54 ms 11308 KB Output is correct
4 Correct 40 ms 10736 KB Output is correct
5 Correct 38 ms 10920 KB Output is correct
6 Correct 37 ms 10684 KB Output is correct
7 Correct 53 ms 11112 KB Output is correct
8 Correct 60 ms 11604 KB Output is correct
9 Correct 55 ms 11628 KB Output is correct
10 Correct 51 ms 11332 KB Output is correct
11 Correct 54 ms 11784 KB Output is correct
12 Correct 52 ms 11088 KB Output is correct
13 Correct 54 ms 11136 KB Output is correct
14 Correct 54 ms 11460 KB Output is correct
15 Correct 52 ms 11488 KB Output is correct
16 Correct 52 ms 11092 KB Output is correct
17 Correct 48 ms 11088 KB Output is correct
18 Correct 56 ms 11356 KB Output is correct
19 Correct 50 ms 11092 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 524 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 353 ms 64272 KB Output is correct
35 Correct 371 ms 65500 KB Output is correct
36 Correct 343 ms 64696 KB Output is correct
37 Correct 402 ms 64412 KB Output is correct
38 Correct 393 ms 64608 KB Output is correct
39 Correct 358 ms 65768 KB Output is correct
40 Correct 356 ms 66904 KB Output is correct
41 Correct 371 ms 65596 KB Output is correct
42 Correct 371 ms 65820 KB Output is correct
43 Correct 133 ms 26564 KB Output is correct
44 Correct 153 ms 39260 KB Output is correct
45 Correct 153 ms 39136 KB Output is correct
46 Correct 172 ms 39360 KB Output is correct
47 Correct 359 ms 67896 KB Output is correct
48 Correct 392 ms 68196 KB Output is correct
49 Correct 397 ms 69032 KB Output is correct
50 Correct 341 ms 68292 KB Output is correct
51 Correct 370 ms 70348 KB Output is correct
52 Correct 385 ms 72852 KB Output is correct
53 Correct 376 ms 68788 KB Output is correct
54 Correct 371 ms 64140 KB Output is correct
55 Correct 326 ms 63356 KB Output is correct
56 Correct 324 ms 63424 KB Output is correct
57 Correct 319 ms 63480 KB Output is correct
58 Correct 389 ms 64360 KB Output is correct
59 Correct 377 ms 65544 KB Output is correct
60 Correct 371 ms 64360 KB Output is correct
61 Correct 367 ms 72744 KB Output is correct
62 Correct 399 ms 69732 KB Output is correct
63 Correct 372 ms 67708 KB Output is correct