답안 #848893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
848893 2023-09-13T16:37:17 Z TheSahib Peru (RMI20_peru) C++17
100 / 100
396 ms 59160 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "peru.h"

#define ll long long
#define pii pair<int, int>

using namespace std;

const int MAX = 25e5 + 5;
const ll oo = 1e18 + 9;
const int mod = 1e9 + 7;

ll dp[MAX];
int* arr;

multiset<ll> st;
deque<int> q;

void erase_front(){
    if(q.size() >= 2){
        int a = q[0];
        int b = q[1];
        st.erase(st.find(dp[b] + arr[a]));
    }
    q.pop_front();
}

void erase_back(){
    int a = q[q.size() - 1];
    int b = q[q.size() - 2];
    st.erase(st.find(dp[a] + arr[b]));
    q.pop_back();
}

void insert(int a){
    q.push_front(a);
    if(q.size() > 1){
        int b = q[1];
        st.insert(dp[b] + arr[a]);
    }
}

int solve(int n, int k, int* v){
    arr = v;
    q.push_front(0);
    dp[0] = arr[0];

    for (int i = 1; i < k; i++)
    {
        while(q.size() && arr[q.front()] <= arr[i]){
            erase_front();
        }
        insert(i);
        
        dp[i] = arr[q.back()];
    }
    
    
    for (int i = k; i < n; i++)
    {
        while(q.size() && arr[q.front()] <= arr[i]){
            erase_front();
        }
        insert(i);

        if(q.back() + k - 1 < i){
            erase_back();
        }

        dp[i] = dp[i - k] + arr[q.back()];
        if(st.size()){
            dp[i] = min(dp[i], *st.begin());
        }
    }
    ll ans = 0;
    for (int i = 0; i <= n - 1; i++)
    {
        ans = (ans * 23 + dp[i]) % mod;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2492 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2516 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2492 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2516 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 53 ms 13228 KB Output is correct
16 Correct 52 ms 13056 KB Output is correct
17 Correct 56 ms 13036 KB Output is correct
18 Correct 38 ms 13016 KB Output is correct
19 Correct 36 ms 12888 KB Output is correct
20 Correct 36 ms 12996 KB Output is correct
21 Correct 55 ms 13060 KB Output is correct
22 Correct 57 ms 12864 KB Output is correct
23 Correct 55 ms 13300 KB Output is correct
24 Correct 56 ms 12880 KB Output is correct
25 Correct 55 ms 12856 KB Output is correct
26 Correct 52 ms 13048 KB Output is correct
27 Correct 53 ms 13088 KB Output is correct
28 Correct 61 ms 13164 KB Output is correct
29 Correct 46 ms 13292 KB Output is correct
30 Correct 54 ms 13060 KB Output is correct
31 Correct 53 ms 13036 KB Output is correct
32 Correct 53 ms 13164 KB Output is correct
33 Correct 54 ms 13028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 13228 KB Output is correct
2 Correct 52 ms 13056 KB Output is correct
3 Correct 56 ms 13036 KB Output is correct
4 Correct 38 ms 13016 KB Output is correct
5 Correct 36 ms 12888 KB Output is correct
6 Correct 36 ms 12996 KB Output is correct
7 Correct 55 ms 13060 KB Output is correct
8 Correct 57 ms 12864 KB Output is correct
9 Correct 55 ms 13300 KB Output is correct
10 Correct 56 ms 12880 KB Output is correct
11 Correct 55 ms 12856 KB Output is correct
12 Correct 52 ms 13048 KB Output is correct
13 Correct 53 ms 13088 KB Output is correct
14 Correct 61 ms 13164 KB Output is correct
15 Correct 46 ms 13292 KB Output is correct
16 Correct 54 ms 13060 KB Output is correct
17 Correct 53 ms 13036 KB Output is correct
18 Correct 53 ms 13164 KB Output is correct
19 Correct 54 ms 13028 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2492 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2516 KB Output is correct
29 Correct 2 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 326 ms 53552 KB Output is correct
35 Correct 321 ms 53724 KB Output is correct
36 Correct 322 ms 53588 KB Output is correct
37 Correct 349 ms 53588 KB Output is correct
38 Correct 341 ms 53848 KB Output is correct
39 Correct 353 ms 53716 KB Output is correct
40 Correct 347 ms 53872 KB Output is correct
41 Correct 351 ms 53672 KB Output is correct
42 Correct 351 ms 53908 KB Output is correct
43 Correct 122 ms 24636 KB Output is correct
44 Correct 138 ms 36424 KB Output is correct
45 Correct 136 ms 36436 KB Output is correct
46 Correct 133 ms 36572 KB Output is correct
47 Correct 338 ms 55840 KB Output is correct
48 Correct 349 ms 56072 KB Output is correct
49 Correct 345 ms 56388 KB Output is correct
50 Correct 297 ms 57468 KB Output is correct
51 Correct 325 ms 56912 KB Output is correct
52 Correct 309 ms 59160 KB Output is correct
53 Correct 308 ms 58088 KB Output is correct
54 Correct 361 ms 53680 KB Output is correct
55 Correct 303 ms 53860 KB Output is correct
56 Correct 295 ms 53584 KB Output is correct
57 Correct 311 ms 53572 KB Output is correct
58 Correct 325 ms 53696 KB Output is correct
59 Correct 333 ms 53588 KB Output is correct
60 Correct 327 ms 53692 KB Output is correct
61 Correct 396 ms 56308 KB Output is correct
62 Correct 368 ms 56032 KB Output is correct
63 Correct 373 ms 55844 KB Output is correct