답안 #746374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746374 2023-05-22T12:05:31 Z doowey Peru (RMI20_peru) C++14
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#include "peru.h"

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

#define fi first
#define se second
#define mp make_pair

const int N = 2511111;
const int MOD = (int)1e9 + 7;
ll dp[N];
ll A[N];
ll ndp[N];
bool off[N];
int pos[N];


int solve(int n, int k, int* v){
    A[0] = (ll)1e18;
    for(int i = 1; i <= n; i ++ ){
        A[i] = v[i - 1];
    }
    priority_queue<pii, vector<pii>, greater<pii>> P;
    deque<pii> L;
    L.push_back(mp(0, -1));
    int id = 0;
    ll mx;
    for(int i = 1; i <= n; i ++ ){

        /*
        while(!L.empty() && A[i] >= A[L.back().fi]){
            if(L.back().se != -1) off[L.back().se] = true;
            L.pop_back();
        }

        while(!L.empty() && L.front().fi <= i - k) {
            if(L.front().se != -1) off[L.front().se] = true;
            L.pop_front();
        }

        if(!L.empty()){
            P.push(mp(A[i] + dp[L.back().fi], id));
            L.back().se = id;
            id ++ ;
        }
        L.push_back(mp(i, -1));
        dp[i] = dp[max(i - k, 0)] + A[L.front().fi];
        while(!P.empty() && off[P.top().se]) P.pop();
        if(!P.empty()) dp[i] = min(dp[i], P.top().fi);
        */
        mx = 0ll;
        dp[i]=(ll)1e18;
        for(int j = i ; j >= max(1, i - k + 1); j -- ){
            mx=max(mx, A[j]);
            dp[i]=min(dp[i], dp[j - 1] + mx);
        }
    }
    int chum = 0;
    int pw = 1;
    for(int i = n; i >= 1; i -- ){
        //cout << dp[i] << " ";
        chum += (pw * 1ll * dp[i]) % MOD;
        if(chum >= MOD) chum -= MOD;
        pw = (pw * 23ll) % MOD;
    }
    return chum;
}

Compilation message

peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:30:9: warning: unused variable 'id' [-Wunused-variable]
   30 |     int id = 0;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -