QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#537086#8040. Let Them Eat Cakerotcar07WA 18ms5428kbC++14595b2024-08-29 20:08:072024-08-29 20:08:07

Judging History

你现在查看的是最新测评结果

  • [2024-08-29 20:08:07]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:5428kb
  • [2024-08-29 20:08:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=1e5+5;
int n;
int a[maxn],l[maxn],r[maxn];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    stack<int> st;a[0]=a[n+1]=n+1;st.push(0);
    for(int i=1;i<=n;i++){
        while(a[st.top()]<a[i]) st.pop();
        l[i]=st.top();st.push(i);
    }
    while(!st.empty()) st.pop();st.push(n+1);
    for(int i=n;i>=1;i--){
        while(a[st.top()]<a[i]) st.pop();
        r[i]=st.top();st.push(i);
    }
    int ans=0;
    for(int i=1;i<=n;i++) ans=max(ans,min(i-l[i],r[i]-i));
    cout<<ans<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

5
1 2 3 4 5

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3780kb

input:

5
1 5 3 4 2

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

2
1 2

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 14ms
memory: 5428kb

input:

100000
100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 9995...

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 18ms
memory: 4944kb

input:

100000
28708 58898 66379 81466 37843 38494 7200 13212 70705 98441 68380 79776 45228 18860 96220 19831 27343 59978 23624 87081 30257 26315 23862 7186 37684 193 70599 29284 14627 30319 51080 95350 17977 32253 58304 19841 67584 44345 69298 63002 48446 5959 8500 12298 59988 55130 56346 5380 23327 13969 ...

output:

27542

result:

wrong answer 1st numbers differ - expected: '11', found: '27542'