daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Feb 21st, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <queue>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <vector>
  6. #include <list>
  7.  
  8. using namespace std ;
  9.  
  10. #define forsn(i, s, n) for (int i = s ; i < n ; i++)
  11. #define forn(i, n) forsn(i, 0, n)
  12. #define fore(i, n) forn(i, n.size())
  13. #define fori(i, n) for (typeof (n.begin()) i = n.begin() ; i != n.end() ; i++)
  14. #define all(n) n.begin(), n.end()
  15. #define pb push_back
  16.  
  17. typedef long long tint ;
  18.  
  19. tint go(const vector <bool> &m, int g, int l)
  20. {
  21.     int e = g - 1 ;
  22.     int a = l - 1, b = 0 ;
  23.     tint r = 0 ;
  24.    
  25.     while (b < m.size() - l)
  26.     {
  27.         int va = a, vb = b ;
  28.        
  29.         e = min(b + g - 1, (int)m.size() - 1) ;
  30.        
  31.         int h = 0 ;
  32.         forsn(i, a + 1, e + 1) if (m[i])
  33.         {
  34.             a = i ;
  35.             h++ ;
  36.         }
  37.        
  38.         for (; h > 0 || m[b] == 0 ; b++) if (m[b]) h-- ;
  39.        
  40.         //cout << b << ' ' << a << ' ' << e << endl ;
  41.        
  42.         if (a - b < l - 1 || va == a || vb == b) return -1 ;
  43.         r += l ;
  44.     }
  45.    
  46.     return r + m.size() - g ;
  47. }
  48.  
  49. int main()
  50. {
  51.     int t ; cin >> t ;
  52.     forn(z, t)
  53.     {
  54.         int l, b, n ; cin >> l >> b >> n ;
  55.         vector <bool> s(n) ;
  56.         forn(i, n)
  57.         {
  58.             char c ; cin >> c ;
  59.             s[i] = (c == '1') ;
  60.         }
  61.        
  62.         int r = go(s, b, l) ;
  63.         if (r == -1) cout << "IMPOSSIBLE" << endl ;
  64.         else cout << r << endl ;
  65.     }
  66.    
  67.     return 0 ;
  68. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top