이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int solve(int n, int k, int *s)
{
int deq[n], dp[n];
int l = 0, r = -1, mul = 1, ans = 0;
for(int i = 0; i < n; i++)
{
while(r >= l && s[deq[r]] <= s[i]) r--;
deq[++r] = i;
if(deq[l] <= i - k) l++;
int nextDp = i >= k ? dp[i - k] : 0;
dp[i] = (nextDp + s[deq[l]]) % MOD;
}
for(int i = n - 1; i >= 0; i--)
{
ans = (1LL * ans + 1LL * dp[i] * mul % MOD) % MOD;
mul = (1LL * mul * 23) % MOD;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |