Description
给定一个长为
的字符串,第
个字符为 o
意味着第
天可以工作,否则不可以。第
天工作后的
天都不能工作。如果工作
天,求哪几天必须工作。
。
Solution
先正向求第 次工作最早在 这一天,再反向求第 次工作最晚在 这一天。如果 那么第 天必须工作。
时间复杂度 。
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
inline int read() {
int x = 0, f = 0; char ch = 0;
while (!isdigit(ch)) f |= ch == '-', ch = getchar();
while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
int pre[N], suf[N];
char s[N];
int main() {
int n = read(), k = read(), c = read();
scanf("%s", s + 1); int len = strlen(s + 1);
for (int i = 1, j = 0; i <= len && j <= k; i++) if (s[i] == 'o') pre[++j] = i, i += c;
for (int i = len, j = k; i && j; i--) if (s[i] == 'o') suf[j--] = i, i -= c;
for (int i = 1; i <= k; i++) if (pre[i] == suf[i] && pre[i]) printf("%d\n", pre[i]);
return 0;
}