답안 #1061742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1061742 2024-08-16T12:30:09 Z TimDee Peru (RMI20_peru) C++17
0 / 100
1 ms 600 KB
#include "peru.h"
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("popcnt,avx2")

#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second 
using ll = long long;
const int N=2005;
ll dp[N];

int solve(int n, int k, int* v){
    const int mod = 1e9+7;

    deque<pi> s;
    deque<pi> d;
    ll ans=0;
    forn(i,n) {
        if (s.size() && s[0].s<=i-k) s.pop_front();
        if (d.size() && d[0].s<=i-k) d.pop_front();
        int tmp;
        while (s.size() && s.back().f <= v[i]) {
            s.pop_back();
        }
        if (s.size()) {
            while (d.size() && d.back().s > s.back().s) d.pop_back();
        } else {
            while (d.size()>1) d.pop_back();
        }
        s.pb({v[i],i});
        dp[i]=s[0].f;
        if (i-k>=0) dp[i]+=dp[i-k];
        dp[i] = min(dp[i],1ll*v[i]+d.back().f);
        d.pb({dp[i],i});
        ans=(ans*23)%mod;
        ans=(ans+dp[i])%mod;
    }
    return ans;
}

Compilation message

peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:26:13: warning: unused variable 'tmp' [-Wunused-variable]
   26 |         int tmp;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -