比赛 20241021 评测结果 AAAAAAAAAA
题目名称 有机化学 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 0.034 s
代码语言 C++ 内存使用 3.53 MiB
提交时间 2024-10-21 09:05:02
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define in inline
#define se second
#define mp make_pair
#define pb push_back
const int N = 300;

ll read(){
	ll x = 0,f = 1;char c = getchar();
	for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
	for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
	return x * f;
}

char c[N];
vector<int>e[N];
int d[N],de[N],ans;

void dfs(int x,int fa){
	if(e[x].size() == 0)return de[x] = 1,void();
	for(int y : e[x]){
		if(y == fa)continue;
		dfs(y,x);
		ans = max(ans,de[x] + de[y]);
		de[x] = max(de[x],de[y] + 1);
		ans = max(ans,de[x]);
	}
}
int now;
void dfs1(int x){
	while(d[x] < 4){
		if(c[++now] == 'C'){
			e[x].pb(now);
			d[now]++;
			dfs1(now);
		}
		d[x]++;
	}
}
int main(){
	freopen("chemistryh.in","r",stdin);
	freopen("chemistryh.out","w",stdout);
	while(cin>>(c + 1)){
		int n = strlen(c + 1);
		now = 1;
		memset(d,0,sizeof d);
		memset(de,0,sizeof de);
		for(int i = 1;i <= n;i++)e[i].clear();
		dfs1(1);
		ans = 1;
		dfs(1,0);
		printf("%d\n",ans);
	}

	return 0;

}