比赛 NOIP模拟赛by mzx Day2 评测结果 WAWWAWWWWW
题目名称 拯救紫萱学姐 最终得分 20
用户昵称 iortheir 运行时间 0.351 s
代码语言 C++ 内存使用 5.08 MiB
提交时间 2016-10-20 21:45:56
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<string>
  4. #include<cstring>
  5. #include<algorithm>
  6.  
  7. using namespace std;
  8.  
  9. const int maxn = 1000000 + 10;
  10.  
  11. char ch[maxn];
  12.  
  13. int f[maxn];
  14.  
  15. int maxm = 0;
  16.  
  17. int ans = 0;
  18.  
  19. int main()
  20. {
  21. freopen("savemzx.in","r",stdin);
  22. freopen("savemzx.out","w",stdout);
  23. scanf("%s",ch+1);
  24. int len = strlen(ch+1);
  25. f[1] = 1;
  26. for(int i=2;i<=len;i++)
  27. {
  28. if(ch[i]!=ch[1])
  29. {
  30. f[i]=i*i;
  31. }
  32. else
  33. {
  34. int j = 1;
  35. while(ch[i]==ch[j]&&i<=len)
  36. {
  37. f[i]=f[j]+(i-j)*(i-j);
  38. j++;
  39. i++;
  40. }
  41. }
  42. }
  43. /*
  44. for(int i=1;i<=len;i++)
  45. {
  46. if(f[i]>maxm)
  47. {
  48. maxm=f[i];
  49. cout<<maxm;
  50. }
  51. }
  52. */
  53. sort(f+1,f+1+len);
  54. ans = f[len] + f[len-1];
  55. cout<<ans;
  56. return 0;
  57. }
  58.