Codeforces Global Round 4 1178B - WOW Factor Solution
Problem Link: https://codeforces.com/contest/1178/problem/B
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- string s;
- cin >> s;
- long long n = s.size();
- long long a[n], b[n], x = 0, y = 0;
- for (int i = 1; i < n; i++) {
- if (s[i] == 'v' && s[i - 1] == 'v') {
- x++;
- }
- a[i] = x;
- }
- for (int i = n - 2; i >= 0; i--) {
- if (s[i] == 'v' && s[i + 1] == 'v') {
- y++;
- }
- b[i] = y;
- }
- long long ans = 0;
- for (int i = 1; i < n - 1; i++) {
- if (s[i] == 'o') {
- ans += (a[i] * b[i]);
- }
- }
- cout << ans << endl;
- }
No comments