-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathB-partial_replacement.cpp
55 lines (48 loc) · 1.02 KB
/
B-partial_replacement.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// problem link: https://codeforces.com/problemset/problem/1506/B
// idea is to find first occuring star and last occurring star
// and then keep on checking at every distance k if there is a need to convert star to cross
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long int t;
cin>>t;
for(int z=0; z<t; z++)
{
long long int n, k;
cin>>n>>k;
string s;
cin>>s;
long long int len = s.length();
long long int start, end, ans=0;
bool first = false;
for(int i=0; i<len; i++)
{
if(s[i] == '*' && first == false)
{
start = end = i;
first = true;
}
if(s[i] == '*') end = i;
}
// *....*..*.*...* k=5
if(start == end) ans = 1;
else
{
long int dist_from_last_appeared_star=1, star = start;
for(int i=start+1; i<end; i++)
{
if(s[i] == '*') star = i;
if(dist_from_last_appeared_star == k)
{
ans++;
dist_from_last_appeared_star = i-star;
}
dist_from_last_appeared_star++;
}
ans += 2;
}
cout<<ans<<endl;
}
return 0;
}