QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#105568#4791. MoviesDeterminantWA 2ms3604kbC++14547b2023-05-14 13:44:522023-05-14 13:44:55

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:44:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3604kb
  • [2023-05-14 13:44:52]
  • 提交

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 x==n?m: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-1-r));
		if(m-sum(l-1)>=l-1&&sum(r+1)>=n-1-r)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: 3568kb

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: 3576kb

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: 0
Accepted
time: 1ms
memory: 3536kb

input:

5 10
14 15 4 12 1
3 9 6 10 13 2 11 7 5 8

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 3604kb

input:

10 10
13 10 4 11 2 15 14 16 1 17
20 18 8 19 6 5 3 9 12 7

output:

9

result:

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