Submission #5401698


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, K;
  string S;
  cin >> N >> K >> S;

  vector<int> v;
  if(S[0] == '1') {
    v.push_back(0);
  }
  char c = S[0];
  for (int i = 0; i < N; i++) {
    int cnt = 1;
    while(i + 1 < N) {
      if(S[i + 1] == c) {
        i++;
        cnt++;
      } else {
        break;
      }
    }
    v.push_back(cnt);
    c = (c == '0') ? '1' : '0';
  }
  
  int l = v.size();
  int *b = new int[l + 1]{};
  for (int i = 0; i < l; i++) {
    b[i + 1] = b[i] + v[i]; 
  }
  
  int ans = 0;
  for (int i = 0; i < l; i += 2) {
    if (i == 0) {
      int r = min(l, 2 * K);
      ans = b[r];
    } else {
      int r = min(l, i + 2 * K);
      ans = max(ans, b[r] - b[i - 1]);
    }
  }
  cout << ans << "\n";
  return 0;
}

Submission Info

Submission Time
Task D - Handstand
User yamakasa
Language C++14 (GCC 5.4.1)
Score 400
Code Size 873 Byte
Status
Exec Time 3 ms
Memory 1272 KB

Test Cases

Set Name Score / Max Score Test Cases
All 400 / 400 sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15
Sample 0 / 0 sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 1 ms 256 KB
sample_02 1 ms 256 KB
sample_03 1 ms 256 KB
testcase_01 1 ms 384 KB
testcase_02 1 ms 384 KB
testcase_03 2 ms 844 KB
testcase_04 1 ms 256 KB
testcase_05 2 ms 1224 KB
testcase_06 2 ms 1224 KB
testcase_07 3 ms 1224 KB
testcase_08 2 ms 1272 KB
testcase_09 2 ms 1224 KB
testcase_10 2 ms 512 KB
testcase_11 1 ms 384 KB
testcase_12 1 ms 384 KB
testcase_13 2 ms 512 KB
testcase_14 2 ms 512 KB
testcase_15 1 ms 256 KB