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 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.