Submission #1220977


Source Code Expand

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int a[100001];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	int cnt=1;
	int mode=0;
	for(int i=0;i<n;i++)
	{
		if(i==0)
		{
			continue;
		}
		if(mode==0)
		{
			if(a[i]==a[i-1]) continue;
			if(a[i]>a[i-1]) mode=1;
			else mode=-1;
		}
		else if(mode==1)
		{
			if(a[i]<a[i-1])
			{
				cnt++;
				mode=0;
			}
		}
		else
		{
			if(a[i]>a[i-1])
			{
				cnt++;
				mode=0;
			}
		}
	}
	cout<<cnt<<'\n';
}

Submission Info

Submission Time
Task A - Sorted Arrays
User zscoder
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1105 Byte
Status AC
Exec Time 12 ms
Memory 892 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 17
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt
Case Name Status Exec Time Memory
sample_01.txt AC 5 ms 892 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_01.txt AC 7 ms 512 KB
subtask_1_02.txt AC 6 ms 512 KB
subtask_1_03.txt AC 4 ms 384 KB
subtask_1_04.txt AC 12 ms 640 KB
subtask_1_05.txt AC 11 ms 640 KB
subtask_1_06.txt AC 12 ms 640 KB
subtask_1_07.txt AC 11 ms 640 KB
subtask_1_08.txt AC 11 ms 640 KB
subtask_1_09.txt AC 12 ms 640 KB
subtask_1_10.txt AC 1 ms 256 KB
subtask_1_11.txt AC 1 ms 256 KB