fork(1) download
  1. //
  2. // Noszály Áron 9a Debreceni Fazekas Mihály Gimnázium
  3. // noszalyaron4@gmail.com
  4. //
  5. // g++ 5.4.0 -std=c++14
  6. //
  7. #include<bits/stdc++.h>
  8. #include<cstdlib>
  9.  
  10. using namespace std;
  11.  
  12. typedef long long ll;
  13. typedef unsigned long long ul;
  14. typedef long double ld;
  15.  
  16. #define all(s) (s).begin(),(s).end()
  17. #define pb push_back
  18. #define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  19. #define INF std::numeric_limits<int>::max()
  20. #define MINF std::numeric_limits<int>::min()
  21. #define tmax(a,b,c) max((a),max((b),(c)))
  22. #define tmin(a,b,c) min((a),min((b),(c)))
  23. #define vpii vector<pair<int,int>>
  24. #define vpll vector<pair<ll,ll>>
  25. #define mp make_pair
  26. #define xx first
  27. #define yy second
  28. #define sz(x) (int)(x).size()
  29.  
  30. #ifndef ONLINE_JUDGE
  31. # define LOG(x) (cerr << #x << " = " << (x) << endl)
  32. #else
  33. # define LOG(x) ((void)0)
  34. #endif
  35.  
  36. const long double PI = acos(-1);
  37.  
  38. int d1[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
  39. int d2[8][2]={{1,0},{0,1},{0,-1},{-1,0},{1,1},{-1,1},{1,-1},{-1,-1}};
  40.  
  41. int a[3000001];
  42. int c[3000001];
  43. int g[3000001];
  44. int t[3000001];
  45. int main()
  46. {
  47. IO;
  48. string tt;cin>>tt;
  49.  
  50. a[sz(tt)-1]=c[sz(tt)-1]=g[sz(tt)-1]=t[sz(tt)-1]=INF;
  51.  
  52. if(tt[sz(tt)-1]=='A') a[sz(tt)-1]=sz(tt)-1;
  53. if(tt[sz(tt)-1]=='C') c[sz(tt)-1]=sz(tt)-1;
  54. if(tt[sz(tt)-1]=='G') g[sz(tt)-1]=sz(tt)-1;
  55. if(tt[sz(tt)-1]=='T') t[sz(tt)-1]=sz(tt)-1;
  56. for(int i=sz(tt)-2;i>=0;i--)
  57. {
  58. a[i]=c[i]=g[i]=t[i]=INF;
  59. if(tt[i]=='A') a[i]=i;
  60. if(tt[i]=='C') c[i]=i;
  61. if(tt[i]=='G') g[i]=i;
  62. if(tt[i]=='T') t[i]=i;
  63.  
  64. a[i]=min(a[i+1], a[i]);
  65. c[i]=min(c[i+1], c[i]);
  66. g[i]=min(g[i+1], g[i]);
  67. t[i]=min(t[i+1], t[i]);
  68. }
  69.  
  70. int ans=0;
  71.  
  72. for(int i=0;i<(sz(tt)-1);++i)
  73. {
  74. if(tt[i]=='A') {
  75.  
  76. if(tmin(c[i],g[i], t[i])!=INF)
  77. {
  78. ans++;
  79. }
  80. }else if(tt[i]=='C')
  81. {
  82. int val=min(g[i], t[i]);
  83. if(val!=INF && val<a[i])
  84. {
  85. ans++;
  86. }
  87. }else if(tt[i]=='G')
  88. {
  89. if(t[i]!=INF && t[i]<min(a[i], c[i]))
  90. {
  91. ans++;
  92. }
  93. }
  94.  
  95. }
  96.  
  97. cout<<ans<<"\n";
  98. }
  99.  
  100.  
Success #stdin #stdout 0s 50344KB
stdin
AATTAA
stdout
2