2 条题解
-
0
#include <bits/stdc++.h> // by:hansang 代码改编于 y总 using namespace std; // 正解 const int N = 2110000; int n, List[N], w[N], head, tail; int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d", &w[i]); w[i + n] = w[i]; // 打印多一遍在后面 } int res = 0, len = n / 2; // 因为复制了一遍在后面,所以res的最大长度就是n/2 head = 0; tail = -1; // 要等加入了数才能开始计算 for(int i = 1; i <= n * 2; i++) { while(head <= tail && List[head] < i - len) head++; // 如果超出范围就 head++ res = max(res, w[List[head]] - List[head] + i + w[i]); while(head <= tail && w[List[tail]] - List[tail] <= w[i] - i) tail--; // 上面的公式因为i+w[i]是固定的,所以要让w[List[]]-w[]最大 List[++tail] = i; } printf("%d\n", res); return 0; } -
0
#include<bits/stdc++.h> //by:hansang 代码改编于 y总 using namespace std; //正解 const int N=2110000; int n, List[N], w[N], head, tail; int main() { scanf("%d",&n); for(int i=1; i<=n; i++) { scanf("%d", &w[i]); w[i+n]=w[i]; //打印多一遍在后面 } int res=0, len=n/2; //因为复制了一遍在后面,所以res的最大长度就是n/2 head=0; tail=-1; //要等加入了数才能开始计算 for(int i=1; i<=n*2; i++) { while(head<=tail && List[head]<i-len) head++; //如果超出范围就 head++ res=max(res, w[List[head]]-List[head]+i+w[i]); while(head<=tail && w[List[tail]]-List[tail]<=w[i]-i) tail--; //上面的公式因为i+w[i]是固定的,所以要让w[List[]]-w[]最大 List[++tail]=i; } printf("%d\n",res); return 0; }
- 1
信息
- ID
- 1376
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- 6
- 标签
- 递交数
- 101
- 已通过
- 28
- 上传者