Submission #1222176
Source Code Expand
#ifdef __APPLE__
#include <cassert>
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <sstream>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cctype>
#include <list>
#include <cmath>
#include <limits>
#include <bitset>
#include <numeric>
#include <climits>
#include <complex>
#else
#include<bits/stdc++.h>
#endif // __APPLE__
using namespace std;
typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef long long int LL;
typedef unsigned long long int ULL;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)
#define ALL(c) (c).begin(),(c).end()
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif
//A
int func1(int n, vector<int> &v)
{
int i=0;
int ans=0;
for(;i<n;i++)
{
//trace(i);
if (v[i]==v[i+1])
{
while(i+1<n && v[i]==v[i+1])
i++;
if(i==(n-1))
ans++;
else
i--;
continue;
}
if(v[i]<=v[i+1])
{
while(i+1<n && v[i]<=v[i+1])
i++;
}
else
{
while(i+1<n && v[i]>=v[i+1])
i++;
}
//trace(i,ans);
ans++;
}
return ans;
}
int main()
{
//fr;fw;
fast_io;
int n;
cin>>n;
VI v(n);
REP(i,0,n)
{
cin>>v[i];
}
int ans1=func1(n,v);
cout<<ans1<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Sorted Arrays |
User |
tomsawyer |
Language |
C++14 (GCC 5.4.1) |
Score |
300 |
Code Size |
2619 Byte |
Status |
AC |
Exec Time |
11 ms |
Memory |
640 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
Status |
|
|
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 |
1 ms |
256 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 |
11 ms |
640 KB |
subtask_1_05.txt |
AC |
11 ms |
640 KB |
subtask_1_06.txt |
AC |
11 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 |
11 ms |
640 KB |
subtask_1_10.txt |
AC |
1 ms |
256 KB |
subtask_1_11.txt |
AC |
1 ms |
256 KB |