Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LightOJ always needs this format for sure..so I made a copy of it...
- #include <bits/stdc++.h>
- #include<vector>
- #define ll long long int
- #define fi freopen("in.txt", "r", stdin)
- #define fo freopen("out.txt", "w", stdout)
- #define m0(a) memset(a , 0 , sizeof(a))
- #define m1(a) memset(a , -1 , sizeof(a))
- #define inf LLONG_MAX
- #define min3(a,b,c) min(a,min(b,c))
- #define max3(a,b,c) max(a,max(b,c))
- #define ones(mask) __builtin_popcount(mask) /// __builtin_popcount : it's a built in function of GCC. Finds out the numbers of 1 in binary representation.
- #define mx 150000
- //#define m 1000000007
- using namespace std;
- char c[1010] = {} ;
- int main()
- {
- ll n ;
- scanf("%lld",&n) ;
- if(n==1)
- {
- printf("YES\n") ;
- return 0 ;
- }
- for(ll i = 0 ; i < n ; i++)
- {
- scanf("%lld",&c[i]) ;
- }
- ll x = 0 ;
- /// 1 = big , 2 = eq , 3 = small ;
- for(ll i = 1 ; i < n ; i++)
- {
- if(x == 0)
- {
- if(c[i] > c[i-1])
- {
- x = 1 ;
- }
- else if(c[i] == c[i-1])
- {
- x = 2 ;
- }
- else if(c[i] < c[i-1])
- {
- x = 3 ;
- }
- }
- else if(x == 1)
- {
- if(c[i] > c[i-1])
- {
- x = 1 ; /// not needed
- }
- else if(c[i] == c[i-1])
- {
- x = 2 ;
- }
- else
- {
- x = 3 ;
- }
- }
- else if(x == 2)
- {
- if(c[i] > c[i-1])
- {
- printf("NO\n") ;
- return 0 ;
- }
- else if(c[i] == c[i-1])
- {
- x = 2 ;
- }
- else
- {
- x = 3 ;
- }
- }
- else if(x == 3)
- {
- if(c[i] > c[i-1])
- {
- printf("NO\n") ;
- return 0 ;
- }
- else if(c[i] == c[i-1])
- {
- printf("NO\n") ;
- return 0 ;
- }
- else
- {
- x = 3 ;
- }
- }
- }
- printf("YES\n") ;
- return 0 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment