智乃的密码
原创
©著作权归作者所有:来自51CTO博客作者whiteawll的原创作品,请联系作者获取转载授权,否则将追究法律责任
https://ac.nowcoder.com/acm/contest/23478/I
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
const int mod = 1e9 + 7;
typedef long long ll;
int n, m, L, R;
string s;
int pre[N][5];
int get (char ch) {
if (ch >= 'a' && ch <= 'z') return 2;
else if (ch >= 'A' && ch <= 'Z') return 1;
else if (ch >= '0' && ch <= '9') return 3;
else return 4;
}
bool ck (map<int, int> cnt) {
int kind = 0;
for (int i =1 ; i <= 4; i ++)
if (cnt[i]) kind ++;
return kind >= 3;
}
void solve() {
cin >> n >> L >> R;
cin >> s;
map<int, int> cnt;
ll ans = 0;
for (int i = 0, j = i; i < n; i ++) {
while (j <= n && !ck(cnt)) {
if (j < n)
cnt[get(s[j])] ++;
j ++;
}
int l = max(j, i + L );
int r = min(n, i + R );
ans += max(r - l + 1, 0);
cnt[get(s[i])] --;
}
cout << ans << endl;
}
int main () {
int t;
t = 1;
while (t --) solve();
return 0;
}
读题错误。单调性分析不对 如果[i, j]已经满足条件,那么[i, j + ...]一定满足条件就不需要继续下去了