-
-
Save jwvg0425/ca34f3472475d0ec9b3ec20bddeb6794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdio.h> | |
#include <memory.h> | |
#include <vector> | |
#include <map> | |
#include <set> | |
#include <queue> | |
#include <stack> | |
#include <string> | |
#include <algorithm> | |
using namespace std; | |
int main() | |
{ | |
int n, m; | |
cin >> n >> m; | |
string str; | |
cin >> str; | |
int nowk = 0; | |
int count = 0; | |
int idx = 0; | |
while (idx < m) | |
{ | |
if (nowk == 0) | |
{ | |
if (str.substr(idx, 3) == "IOI") | |
{ | |
nowk++; | |
idx += 2; | |
} | |
idx++; | |
continue; | |
} | |
if (str.substr(idx, 2) == "OI") | |
{ | |
nowk++; | |
idx += 2; | |
continue; | |
} | |
count += max(0, nowk - n + 1); | |
nowk = 0; | |
} | |
count += max(0, nowk - n + 1); | |
cout << count << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment