Codeforces Global Round 4 1178B - WOW Factor Solution



  Problem Link: https://codeforces.com/contest/1178/problem/B

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int main() {
  10. string s;
  11. cin >> s;
  12. long long n = s.size();
  13. long long a[n], b[n], x = 0, y = 0;
  14. for (int i = 1; i < n; i++) {
  15. if (s[i] == 'v' && s[i - 1] == 'v') {
  16. x++;
  17. }
  18. a[i] = x;
  19. }
  20. for (int i = n - 2; i >= 0; i--) {
  21. if (s[i] == 'v' && s[i + 1] == 'v') {
  22. y++;
  23. }
  24. b[i] = y;
  25. }
  26. long long ans = 0;
  27. for (int i = 1; i < n - 1; i++) {
  28. if (s[i] == 'o') {
  29. ans += (a[i] * b[i]);
  30. }
  31. }
  32. cout << ans << endl;
  33. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.