fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23.  
  24.  
  25. vector<int> a;
  26. void consistency(string s) {
  27.  
  28. int n = s.size();
  29. int L = 0;
  30. int LC = 0;
  31. int LCT = 0;
  32. for(int i=0; i<n; i++){
  33. if(s[i] == 'L') L++;
  34. else if(s[i] == 'C') LC += L;
  35. else if(s[i] == 'T') LCT += LC;
  36. }
  37.  
  38. int T = 0;
  39. int CT = 0;
  40. for(int i=n-1; i>=0; i--){
  41. if(s[i] == 'T') T++;
  42. else if(s[i] == 'C') CT++;
  43.  
  44. }
  45.  
  46. int LCTT = LCT + LC;
  47. int LLCT = LCT + CT;
  48. int ans = max(LCTT, LLCT);
  49.  
  50. int ct = 0;
  51. int l = 0;
  52. int t = T;
  53. for(int i=0; i<n-1; i++){
  54. if(s[i] == 'L') l++;
  55. else if(s[i] == 'T') t--;
  56.  
  57. ct = max(ct, l * t);
  58. }
  59.  
  60. int LCCT = LCT + ct;
  61.  
  62. ans = max(ans, LCCT);
  63.  
  64. cout << ans << endl;
  65.  
  66. }
  67.  
  68. void solve() {
  69.  
  70. string s;
  71. cin >> s;
  72. consistency(s) ;
  73.  
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. int32_t main() {
  81. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  82.  
  83. int t = 1;
  84. while (t--) {
  85. solve();
  86. }
  87.  
  88. return 0;
  89. }
Success #stdin #stdout 0s 5304KB
stdin
LMCT
stdout
2