답안 #1061768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061768 2024-08-16T13:08:10 Z MilosMilutinovic Peru (RMI20_peru) C++14
18 / 100
600 ms 10532 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) {
  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);
    int mx = 0;
    for (int p = j; p <= i; p++) {
      mx = max(mx, v[p]);
    }
    dp[i] = min(dp[i], (j == 0 ? 0LL : dp[j - 1]) + mx);
  }
  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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 336 ms 5980 KB Output is correct
16 Correct 278 ms 6284 KB Output is correct
17 Correct 167 ms 6448 KB Output is correct
18 Correct 181 ms 5720 KB Output is correct
19 Correct 206 ms 5724 KB Output is correct
20 Correct 381 ms 5724 KB Output is correct
21 Correct 363 ms 6216 KB Output is correct
22 Correct 553 ms 6544 KB Output is correct
23 Execution timed out 657 ms 10532 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 336 ms 5980 KB Output is correct
2 Correct 278 ms 6284 KB Output is correct
3 Correct 167 ms 6448 KB Output is correct
4 Correct 181 ms 5720 KB Output is correct
5 Correct 206 ms 5724 KB Output is correct
6 Correct 381 ms 5724 KB Output is correct
7 Correct 363 ms 6216 KB Output is correct
8 Correct 553 ms 6544 KB Output is correct
9 Execution timed out 657 ms 10532 KB Time limit exceeded
10 Halted 0 ms 0 KB -