Submission #7643405


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int x[200000];
vector<int> v;
signed main(){
	int a,b;
	cin>>a>>b;
	int cnt=1,z=-1,vz,ans=0,an=0;
	bool bo=false,boo=false;
	v.push_back(0);
	f(i,a){
		cin>>x[i];
		if(z<x[i]){
			vz=i;
			z=max(z,x[i]);
			if(boo){
				v.push_back(i-1);
				boo=false;
				bo=false;
			}
		}
		else{
			if(!bo){
				v.push_back(vz);
				bo=true;
			}
			boo=true;
		}
	}
	v.push_back(a);
	for(int i=1;i+1<v.size();i+=2){
		ans+=max((int)0,min({b-(v[i+1]-v[i]+1),v[i+2]-v[i+1],v[i]-v[i-1]}));
	}
	f(i,a){
		if(i){
			if(x[i]>x[i-1])cnt++;
			else{
				an+=max((int)0,cnt-b+1);
				cnt=1;
			}
		}
	}
	an+=max((int)0,cnt-b+1);
	cout<<a-b+1-ans-max((int)0,an-1)<<endl;
}

Submission Info

Submission Time
Task B - Sorting a Segment
User mutuhuhihusenonu
Language C++14 (GCC 5.4.1)
Score 0
Code Size 992 Byte
Status WA
Exec Time 63 ms
Memory 2676 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 10
WA × 22
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01-01.txt AC 1 ms 256 KB
01-02.txt AC 1 ms 256 KB
01-03.txt WA 48 ms 1536 KB
01-04.txt WA 49 ms 1536 KB
01-05.txt WA 33 ms 1656 KB
01-06.txt AC 40 ms 1280 KB
01-07.txt AC 59 ms 1792 KB
01-08.txt WA 60 ms 1792 KB
01-09.txt WA 59 ms 1792 KB
01-10.txt WA 62 ms 2676 KB
01-11.txt WA 59 ms 1792 KB
01-12.txt WA 59 ms 1792 KB
01-13.txt WA 61 ms 2676 KB
01-14.txt WA 60 ms 1792 KB
01-15.txt WA 59 ms 1792 KB
01-16.txt WA 62 ms 2676 KB
01-17.txt WA 59 ms 1792 KB
01-18.txt WA 59 ms 1792 KB
01-19.txt WA 63 ms 2676 KB
01-20.txt AC 59 ms 1792 KB
01-21.txt WA 59 ms 1792 KB
01-22.txt WA 60 ms 1792 KB
01-23.txt WA 59 ms 1792 KB
01-24.txt WA 62 ms 2676 KB
01-25.txt AC 59 ms 1792 KB
01-26.txt WA 59 ms 1792 KB
01-27.txt WA 60 ms 1792 KB
01-28.txt AC 59 ms 1792 KB
01-29.txt WA 59 ms 1792 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB
sample-03.txt AC 1 ms 256 KB