QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#105556 | #4791. Movies | Determinant | WA | 2ms | 3756kb | C++14 | 580b | 2023-05-14 13:12:22 | 2023-05-14 13:12:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;const int N=1e5+7;
int n,m,ans=1e9,minn=1e9,fl=1,a[N],b[N],c[N];
int sum(int x){return a[c[x]]-x;}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){scanf("%d",&a[i]);b[i]=a[i];if(a[i]>a[i-1])fl=0;}
if(fl){puts("0");return 0;}sort(b+1,b+n+1);
for(int i=1;i<=n;++i)c[lower_bound(b+1,b+n+1,a[i])-b]=i;
for(int r=1,l=1;r<n;++r){
if(c[r]<c[r-1])l=r;int x=max(2*(l-1)-1,2*(n-r));
if((n-sum(l)-1>=x&&sum(r)-sum(l)>=n-1-r)||(sum(r)>=x&&sum(r)-sum(l)>=l-1))
ans=min(ans,x);
}
printf("%d\n",ans==1e9?-1:ans+1);
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3756kb
input:
5 5 3 1 5 2 4 6 8 7 9 10
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3516kb
input:
5 10 3 5 9 15 4 6 11 13 1 7 10 12 14 2 8
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 3708kb
input:
5 10 14 15 4 12 1 3 9 6 10 13 2 11 7 5 8
output:
5
result:
wrong answer 1st numbers differ - expected: '3', found: '5'