比赛 20241021 评测结果 AAAAAAAAAA
题目名称 有机化学 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 0.034 s
代码语言 C++ 内存使用 3.53 MiB
提交时间 2024-10-21 09:05:02
显示代码纯文本
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define pii pair<int,int>
  5. #define fi first
  6. #define in inline
  7. #define se second
  8. #define mp make_pair
  9. #define pb push_back
  10. const int N = 300;
  11.  
  12. ll read(){
  13. ll x = 0,f = 1;char c = getchar();
  14. for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
  15. for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
  16. return x * f;
  17. }
  18.  
  19. char c[N];
  20. vector<int>e[N];
  21. int d[N],de[N],ans;
  22.  
  23. void dfs(int x,int fa){
  24. if(e[x].size() == 0)return de[x] = 1,void();
  25. for(int y : e[x]){
  26. if(y == fa)continue;
  27. dfs(y,x);
  28. ans = max(ans,de[x] + de[y]);
  29. de[x] = max(de[x],de[y] + 1);
  30. ans = max(ans,de[x]);
  31. }
  32. }
  33. int now;
  34. void dfs1(int x){
  35. while(d[x] < 4){
  36. if(c[++now] == 'C'){
  37. e[x].pb(now);
  38. d[now]++;
  39. dfs1(now);
  40. }
  41. d[x]++;
  42. }
  43. }
  44. int main(){
  45. freopen("chemistryh.in","r",stdin);
  46. freopen("chemistryh.out","w",stdout);
  47. while(cin>>(c + 1)){
  48. int n = strlen(c + 1);
  49. now = 1;
  50. memset(d,0,sizeof d);
  51. memset(de,0,sizeof de);
  52. for(int i = 1;i <= n;i++)e[i].clear();
  53. dfs1(1);
  54. ans = 1;
  55. dfs(1,0);
  56. printf("%d\n",ans);
  57. }
  58.  
  59. return 0;
  60.  
  61. }