Submission #1222516
Source Code Expand
#include<queue> #include<cmath> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define ll long long #define mod 1000000007 using namespace std; int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } const int N=1e5+10; const int M=1e7+10; int a[N]; int main() { int n; while(~scanf("%d",&n)) { int ans=1,x,pre,flag=-1; for(int i=0; i<n; i++) { x=read(); if(i>0){ if(flag==-1){ if(x>pre) flag=0; else if(x<pre) flag=1; } else{ if(x>pre&&flag==1){ ans++; flag=-1; } if(x<pre&&flag==0){ ans++; flag=-1; } } } pre=x; } printf("%d\n",ans); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Sorted Arrays |
User | ACforgood |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 1228 Byte |
Status | AC |
Exec Time | 9 ms |
Memory | 256 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 | 256 KB |
subtask_1_02.txt | AC | 5 ms | 256 KB |
subtask_1_03.txt | AC | 3 ms | 256 KB |
subtask_1_04.txt | AC | 9 ms | 256 KB |
subtask_1_05.txt | AC | 9 ms | 256 KB |
subtask_1_06.txt | AC | 9 ms | 256 KB |
subtask_1_07.txt | AC | 9 ms | 256 KB |
subtask_1_08.txt | AC | 9 ms | 256 KB |
subtask_1_09.txt | AC | 9 ms | 256 KB |
subtask_1_10.txt | AC | 1 ms | 256 KB |
subtask_1_11.txt | AC | 1 ms | 256 KB |