Advertisement
Tarche

SocialDistance - CodeForces

Jun 16th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. //Lucas Hernán Tarche - ESCCP - 2020
  2. //CodeForces
  3. #include <iostream>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     int t, n, k;
  11.     string in;
  12.     cin >> t;
  13.     for (int i = 0; i < t; i++) {
  14.         cin >> n >> k >> in;
  15.         vector<bool> seats(n, true);
  16.         for (int j = 0; j < n; j++) {
  17.             if (in[j] == '1') {
  18.                 for (int m = j - k; m <= j + k; m++) {
  19.                     if (m < 0 || m >= n) continue;
  20.                     seats[m] = false;
  21.                 }
  22.             }
  23.         }
  24.         int counter = 0;
  25.         for (int j = 0; j < n; j++) {
  26.             if (seats[j]) {
  27.                 counter++;
  28.                 for (int m = j - k; m <= j + k; m++) {
  29.                     if (m < 0 || m >= n) continue;
  30.                     seats[m] = false;
  31.                 }
  32.             }
  33.         }
  34.         cout << counter << '\n';
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement