답안 #849398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849398 2023-09-14T14:52:36 Z TahirAliyev Peru (RMI20_peru) C++17
49 / 100
261 ms 72132 KB
#include "peru.h"
#include <bits/stdc++.h>

#define ll long long
#define oo 1e17
#define pii pair<int, int>

using namespace std;

const int MAX = 25e5, MOD = 1e9 + 7;
ll arr[MAX];
ll dp[MAX];
ll val[MAX];
priority_queue<pair<ll, int>> s;
bool d[MAX];
deque<int> dq;

void clearQ(){
    while(d[s.top().second]){
        s.pop();
    }
}

int solve(int n, int k, int* v){
    for(int i = 0; i < n; i++){
        arr[i + 1] = v[i];
    }
    dq.push_back(1);
    dp[1] = arr[1];
    for(int i = 2; i <= n; i++){
        while(dq.size() && arr[dq.back()] <= arr[i]){
            if(dq.size() > 1) d[dq.back()] = 1;
            dq.pop_back();
        }
        if(dq.size() && dq.front() == i - k){
            dq.pop_front();
            if(dq.size()){
                d[dq.front()] = 1;
            }
        }
        dp[i] = oo;
        if(dq.size()){
            val[i] = dp[dq.back()] + arr[i];
            s.push({-val[i], i});
            clearQ();
            dp[i] = -s.top().first;
        }
        dq.push_back(i);
        dp[i] = min(dp[i], arr[dq.front()] + dp[max(0, i - k)]);
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans *= 23;
        ans += dp[i];
        ans %= MOD;
    }
    return ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8536 KB Output is correct
4 Correct 1 ms 8536 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 2 ms 8536 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 1 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8536 KB Output is correct
4 Correct 1 ms 8536 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 2 ms 8536 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 1 ms 8536 KB Output is correct
15 Correct 37 ms 21072 KB Output is correct
16 Correct 37 ms 21072 KB Output is correct
17 Correct 37 ms 21072 KB Output is correct
18 Correct 37 ms 21072 KB Output is correct
19 Correct 38 ms 19280 KB Output is correct
20 Correct 41 ms 19536 KB Output is correct
21 Correct 41 ms 21072 KB Output is correct
22 Correct 41 ms 21328 KB Output is correct
23 Correct 41 ms 21328 KB Output is correct
24 Correct 39 ms 21072 KB Output is correct
25 Correct 41 ms 19280 KB Output is correct
26 Correct 36 ms 19280 KB Output is correct
27 Correct 37 ms 21092 KB Output is correct
28 Correct 37 ms 21328 KB Output is correct
29 Correct 37 ms 19536 KB Output is correct
30 Correct 37 ms 21072 KB Output is correct
31 Correct 36 ms 21072 KB Output is correct
32 Correct 39 ms 21328 KB Output is correct
33 Correct 36 ms 21072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 21072 KB Output is correct
2 Correct 37 ms 21072 KB Output is correct
3 Correct 37 ms 21072 KB Output is correct
4 Correct 37 ms 21072 KB Output is correct
5 Correct 38 ms 19280 KB Output is correct
6 Correct 41 ms 19536 KB Output is correct
7 Correct 41 ms 21072 KB Output is correct
8 Correct 41 ms 21328 KB Output is correct
9 Correct 41 ms 21328 KB Output is correct
10 Correct 39 ms 21072 KB Output is correct
11 Correct 41 ms 19280 KB Output is correct
12 Correct 36 ms 19280 KB Output is correct
13 Correct 37 ms 21092 KB Output is correct
14 Correct 37 ms 21328 KB Output is correct
15 Correct 37 ms 19536 KB Output is correct
16 Correct 37 ms 21072 KB Output is correct
17 Correct 36 ms 21072 KB Output is correct
18 Correct 39 ms 21328 KB Output is correct
19 Correct 36 ms 21072 KB Output is correct
20 Correct 2 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8536 KB Output is correct
23 Correct 1 ms 8536 KB Output is correct
24 Correct 1 ms 8536 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 1 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 1 ms 8536 KB Output is correct
29 Correct 2 ms 8536 KB Output is correct
30 Correct 1 ms 8536 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 2 ms 8536 KB Output is correct
33 Correct 1 ms 8536 KB Output is correct
34 Correct 249 ms 71600 KB Output is correct
35 Correct 246 ms 71840 KB Output is correct
36 Correct 244 ms 71628 KB Output is correct
37 Correct 249 ms 71624 KB Output is correct
38 Correct 250 ms 71760 KB Output is correct
39 Correct 251 ms 71692 KB Output is correct
40 Correct 261 ms 71784 KB Output is correct
41 Correct 253 ms 71608 KB Output is correct
42 Correct 254 ms 71724 KB Output is correct
43 Correct 96 ms 34508 KB Output is correct
44 Correct 137 ms 48992 KB Output is correct
45 Correct 142 ms 49744 KB Output is correct
46 Correct 140 ms 49104 KB Output is correct
47 Correct 252 ms 71880 KB Output is correct
48 Correct 253 ms 71784 KB Output is correct
49 Correct 256 ms 72132 KB Output is correct
50 Incorrect 249 ms 72128 KB Output isn't correct
51 Halted 0 ms 0 KB -