B
答案要么是0 要么是1
所以你全部填0或者要么填1然后算就好了
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5+10;
int n;void solve()
{//全0 全1?string str;cin>>str;n = str.size();string str1 = str;int ans1 = 0;int tem = 0;for(int i=0;i<n;i++){if((str[i]=='1'||str[i]=='?')){tem++;}else tem = 0;ans1 = max(ans1,tem);}int ans2 = 0,tem1 = 0;for(int i=0;i<n;i++){if((str[i]=='0'||str[i]=='?')){tem1++;}else tem1 = 0;ans2 = max(ans2,tem1);} cout<<max(ans1,ans2)<<"\n";}int main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _;_ = 1;while(_--)solve();
}
C
你先算出每一段的起码的长度就好了
t对相邻 故需要连续的1 t+1个
剩余的1为 k-t-1 且需要这么多0
再多的数字的话你直接填上 0 就好了
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5+10;int n,k,t;
void solve()
{//t+1个连续的1//k-t-1剩余的1 至少k-t-1个0//n>上面cin>>n>>k>>t;int s11 = t+1;int s1 = k-t-1;int s0 = k-t-1;if(n<s0+s1+s11||s1<0){cout<<-1;return;} int s00 = n-s0-s1-s11;while(s11--)cout<<1;while(s1--)cout<<"01";while(s00--)cout<<"0";}int main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _;_ = 1;while(_--)solve();
}