比赛 |
20240913练习 |
评测结果 |
AEEETEEETA |
题目名称 |
奶牛排队 |
最终得分 |
20 |
用户昵称 |
李奇文 |
运行时间 |
5.457 s |
代码语言 |
C++ |
内存使用 |
4.58 MiB |
提交时间 |
2024-09-13 20:22:01 |
显示代码纯文本
- #include<bits/stdc++.h>
- using namespace std;
- struct node{
- int l,r;
- }a[100005],b[100005];
- int n,c[100005],ans,j;
- int main(){
- freopen("tahort.in","r",stdin);
- freopen("tahort.out","w",stdout);
- scanf("%d",&n);
- for(int i=1;i<=n;i++){
- scanf("%d",&c[i]);
- a[i].l=a[i].r=b[i].l=b[i].r=i;
- }
- for(int i=1;i<=n;i++){
- j=i+1;
- while(true){
- if(c[i]<c[j]){
- a[i].r=j;
- j++;
- }else{
- break;
- }
- }
- }
- for(int i=n;i>=1;i--){
- j=i-1;
- while(true){
- if(c[i]>c[j]){
- b[i].l=j;
- j--;
- }else{
- break;
- }
- }
- }
- for(int i=1;i<=n;i++){
- if(a[i].r==i) continue;
- for(int k=i;k<=n;k++){
- if(b[k].l==k) continue;
- if((a[i].l==b[k].l)&&a[i].r==b[k].r){
- ans=max(ans,a[i].r-a[i].l+1);
- }else if(a[i].r==b[k].r){
- ans=max(ans,min(a[i].r-a[i].l+1,b[k].r-b[k].l+1));
- }
- }
- }
- printf("%d",ans);
- return 0;
- }