如果你源测试点100,hack数据全错

P1725 琪露诺

BIOS @ 2024-02-08 11:48:57

刚开始的区间[1,l-1]是不能走的,应该赋为负无穷避免必不可能发生的转移,原测试点没有考虑这个问题。


by wanghaoze1126 @ 2024-02-08 19:12:21

还是过不了 代码:

#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7, N = 2e5 + 5;
int n, l, r, ans = -inf;
int a[N], dp[N];
deque<int> q;

int main()
{
    scanf("%d%d%d", &n, &l, &r);
    for (int i = 0; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i < l; ++i) dp[i] = -inf;
    for (int i = l; i <= n; ++i)
    {
        while (!q.empty() && q.back() < i - r) q.pop_back();
        while (!q.empty() && dp[q.front()] < dp[i - l]) q.pop_front();
        q.push_back(i - l);
        dp[i] = dp[q.front()] + a[i];
        if (i + r > n) ans = max(dp[i], ans);
    }
    printf("%d\n", ans);
    return 0;
}

|