QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#105556#4791. MoviesDeterminantWA 2ms3756kbC++14580b2023-05-14 13:12:222023-05-14 13:12:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-14 13:12:24]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3756kb
  • [2023-05-14 13:12:22]
  • 提交

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);
}

Details

Tip: Click on the bar to expand more detailed information

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'