Submission #1470097
Source Code Expand
// This amazing code is by Eric Sunli Chen. #include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <cstdio> #include <cstdlib> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; template<typename T> void get_int(T &x) { char t=getchar(); bool neg=false; x=0; for(; (t>'9'||t<'0')&&t!='-'; t=getchar()); if(t=='-')neg=true,t=getchar(); for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0'; if(neg)x=-x; } template<typename T> void print_int(T x) { if(x<0)putchar('-'),x=-x; short a[20]= {},sz=0; while(x>0)a[sz++]=x%10,x/=10; if(sz==0)putchar('0'); for(int i=sz-1; i>=0; i--)putchar('0'+a[i]); } #define ff first #define ss second #define pb push_back #define mp make_pair #define get1(a) get_int(a) #define get2(a,b) get1(a),get1(b) #define get3(a,b,c) get1(a),get2(b,c) #define printendl(a) print_int(a),puts("") typedef long long LL; typedef unsigned long long uLL; typedef pair<int,int> pii; const int inf=0x3f3f3f3f; const LL Linf=1ll<<61; const double pi=acos(-1.0); int n,a[100111]; int main() { get1(n); for(int i=1;i<=n;i++)get1(a[i]); int cur=0,ans=0;//cur=1 - inc cur=2 - dec for(int i=1;i<=n;i++) { if(i==1||(cur==1&&a[i]<a[i-1])||(cur==2&&a[i]>a[i-1])) { cur=0; ans++; } else { if(a[i]>a[i-1])cur=1;else if(a[i]<a[i-1])cur=2; } } printendl(ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Sorted Arrays |
User | OhWeOnFire |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 1534 Byte |
Status | AC |
Exec Time | 9 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 | 6 ms | 512 KB |
subtask_1_02.txt | AC | 5 ms | 384 KB |
subtask_1_03.txt | AC | 3 ms | 384 KB |
subtask_1_04.txt | AC | 9 ms | 640 KB |
subtask_1_05.txt | AC | 9 ms | 640 KB |
subtask_1_06.txt | AC | 9 ms | 640 KB |
subtask_1_07.txt | AC | 9 ms | 640 KB |
subtask_1_08.txt | AC | 9 ms | 640 KB |
subtask_1_09.txt | AC | 9 ms | 640 KB |
subtask_1_10.txt | AC | 1 ms | 256 KB |
subtask_1_11.txt | AC | 1 ms | 256 KB |