有个01串,每次可以将k个01串逆转,求最少操作次数的情况下的最小k
区间修改用差分实现
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i(j);i<=k;++i)
#define drp(i,j,k) for(int i(j);i>=k;--i)
#define repg(x) for(int i(G.head[x]);i;i=G.next[i])
#define bug cout<<"~~~~~~~~~~~~~"<<'
';
using std::cin;
using std::cout;
const int N = 5e3 + 79;
int n;
int a[N], b[N], sum, tag, ans=N,anss;
char op;
int main() {
cin >> n;
rep(i, 1, n) {
cin >> op;
a[i] = (op == 'F') ;
}
rep(k, 1, n) {
int now=0 , tot = 0;
int flag = 1;
memset(b, 0, sizeof b);
rep(i, 1, n) {
now ^= b[i];
if(a[i]^now == 0) {
if(i + k - 1 > n) {
flag = 0;
break;
}
tot++;
now^=1;
b[i+k]^=1;
}
}
if(flag){
if(tot<ans){
ans=tot;
anss=k;
}
}
}
cout<<anss<<' '<<ans<<'
';
return 0;
}