跳到正文

个人记录

T758328 FEB(feb)

sixwl约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年5月5日
更新
2026年5月5日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1

思路: 靠边的 F:能凑出0 到 c里任意次数

夹在中间的 F:有最小、最大次数,只能凑和它俩奇偶一样的数,每次只能是 2

把所有段的最小、最大加起来,就是整体的最小和最大值。

代码:

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long

string s,t;
int n,l,r,d;
signed main(){
	cin>>n>>s;
	t=s;
	d=2-(s[0]=='F' || s[n-1]=='F');
	for(; r<n-1 && s[r]=='F'; r++){

	}
	for(int i=r+1; i<n; i++){
		if(s[i]=='F'){
			t[i]=t[i-1];
			s[i]=s[i-1]=='E'?'B':'E';
		}
		l+=s[i]==s[i-1];
		r+=t[i]==t[i-1];
	}
	cout<<(r-l)/d+1<<"\n";
	for(int i=l; i<=r; i+=d){
		cout<<i<<"\n";
	}
	return 0;
}
原文