shamiul93

CF 424 - A

Jul 13th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. // LightOJ always needs this format for sure..so I made a copy of it...
  2. #include <bits/stdc++.h>
  3. #include<vector>
  4. #define ll                                      long long int
  5. #define fi                                      freopen("in.txt", "r", stdin)
  6. #define fo                                      freopen("out.txt", "w", stdout)
  7. #define m0(a) memset(a , 0 , sizeof(a))
  8. #define m1(a) memset(a , -1 , sizeof(a))
  9. #define inf LLONG_MAX
  10. #define min3(a,b,c) min(a,min(b,c))
  11. #define max3(a,b,c) max(a,max(b,c))
  12. #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.
  13. #define mx 150000
  14. //#define m 1000000007
  15.  
  16. using namespace std;
  17.  
  18. char c[1010] = {} ;
  19.  
  20. int main()
  21. {
  22.     ll n ;
  23.     scanf("%lld",&n) ;
  24.  
  25.     if(n==1)
  26.     {
  27.         printf("YES\n") ;
  28.         return 0 ;
  29.     }
  30.  
  31.     for(ll i = 0 ; i < n ; i++)
  32.     {
  33.         scanf("%lld",&c[i]) ;
  34.     }
  35.  
  36.     ll x = 0 ;
  37.  
  38.     /// 1 = big , 2 = eq , 3 = small ;
  39.  
  40.     for(ll i = 1 ; i < n ; i++)
  41.     {
  42.         if(x == 0)
  43.         {
  44.             if(c[i] > c[i-1])
  45.             {
  46.                 x = 1 ;
  47.             }
  48.             else if(c[i] == c[i-1])
  49.             {
  50.                 x = 2 ;
  51.             }
  52.             else if(c[i] < c[i-1])
  53.             {
  54.                 x = 3 ;
  55.             }
  56.         }
  57.         else if(x == 1)
  58.         {
  59.             if(c[i] > c[i-1])
  60.             {
  61.                 x = 1 ; /// not needed
  62.             }
  63.             else if(c[i] == c[i-1])
  64.             {
  65.                 x = 2 ;
  66.             }
  67.             else
  68.             {
  69.                 x = 3 ;
  70.             }
  71.         }
  72.         else if(x == 2)
  73.         {
  74.             if(c[i] > c[i-1])
  75.             {
  76.                 printf("NO\n") ;
  77.                 return 0 ;
  78.             }
  79.             else if(c[i] == c[i-1])
  80.             {
  81.                 x = 2 ;
  82.             }
  83.             else
  84.             {
  85.                 x = 3 ;
  86.             }
  87.         }
  88.         else if(x == 3)
  89.         {
  90.             if(c[i] > c[i-1])
  91.             {
  92.                 printf("NO\n") ;
  93.                 return 0 ;
  94.             }
  95.             else if(c[i] == c[i-1])
  96.             {
  97.                 printf("NO\n") ;
  98.                 return 0 ;
  99.             }
  100.             else
  101.             {
  102.                 x = 3 ;
  103.             }
  104.         }
  105.     }
  106.  
  107.     printf("YES\n") ;
  108.  
  109.     return 0 ;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment