Advertisement
IlidanBabyRage

snarkhome.cpp

Jun 3rd, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.    
  7.     int x, s, n;
  8.     cin >> x >> s >> n;
  9.     int *ar = new int[x];
  10.     for (int i = 0; i < x; i++)
  11.         ar[i] = 0;
  12.     int bread;
  13.     for (int i = 0; i < n; i++){
  14.         cin >> bread;
  15.         ar[bread - 1] = -1;
  16.     }
  17.     // START:
  18.     // {
  19.         for (int i = x - 2; i >= 0; i--){
  20.             if (ar[i] == -1)
  21.                 continue;
  22.             int min = -1;
  23.             int lim = (i + s) > (x - 1) ? x - 1 : i + s;
  24.             for (int j = i + 1; j <= lim; j++){
  25.                 if (ar[j] != -1)
  26.                     if (ar[j] < min || min == -1)
  27.                         min = ar[j];
  28.             }
  29.             if (min == -1){
  30.                 cout << "YES" << endl;
  31.                 return 0;
  32.             }
  33.             ar[i] = min + 1;
  34.         }
  35.         // for (int i = 0; i < x; i++){
  36.             // cout << ar[i] << " ";
  37.         // }
  38.         // cout << endl;
  39.     // }
  40.     for (int i = 1; i < x - 1; i++){
  41.         int lim = (i + s) > (x - 1) ? x - 1 : i + s;
  42.         int min_count = 1, count = 0, min = -1;
  43.         bool dif = false;
  44.         // cout << "lim : " << lim << endl;
  45.         for (int j = i; j < lim - 1; j++){
  46.             if (ar[j] < 0){
  47.                 if (ar[j + 1] > 0 && (min == -1 || ar[j + 1] < min))
  48.                     min = ar[j + 1];
  49.                     // cout << j + 1 << " " <<  min << endl;
  50.                 continue;
  51.             }
  52.             if (ar[j + 1] > 0){
  53.                 if (ar[j] != ar[j + 1]){
  54.                     dif = true;
  55.                     count = min_count;
  56.                     min_count = 0;
  57.                 }
  58.                 min = ar[j + 1];
  59.                 // cout << j + 1 << " " <<  min << endl;
  60.             }
  61.             min_count++;
  62.         }
  63.         if ((min_count < min && (count + min_count - 1) < min)){
  64.             cout << "YES" << endl;
  65.             // cout << min << endl;
  66.             // cout << count << " " << min_count << endl << dif << endl;
  67.             return 0;
  68.         }
  69.     }
  70.  
  71.     // int tmp;
  72.     // do{
  73.     //  cin >> tmp;
  74.     //  if (tmp > 0){
  75.     //      ar[tmp - 1] = -1;
  76.     //      goto START;
  77.     //  }
  78.     // }while(tmp > 0);
  79.     cout << "NO" << endl;
  80.  
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement