-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5525.cpp
More file actions
38 lines (36 loc) · 839 Bytes
/
5525.cpp
File metadata and controls
38 lines (36 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int main()
{
io;
int N,M,res=0;
cin>>N>>M;
vector<int> counting(M);
for(int i=0;i<M;i++){
char c;
cin>>c;
if(i==0) {
if(c=='I') counting[i]=1;
else counting[i]=-1;
continue;
}
if(c=='I'){
if(i>=2&&counting[i-2]>0&&counting[i-1]==-1){
if(counting[i-2]==N+1)
counting[i]=counting[i-2];
else
counting[i]=counting[i-2]+1;
if(counting[i]==N+1)
res++;
}else counting[i]=1;
}else{
counting[i]=-1;
}
}
cout<<res;
return 0;
}