ChinaNumberOne's blog

By ChinaNumberOne, history, 5 years ago, In English

Hey!

so In the contest yesterday, I tried to solve problem B, but I think I misunderstanded it, and even after I read the tutorial I still did not get it!!

I understood that I have to print the number of ways of getting "wow" from string s. My idea was to calculate number of 'v' before(prev) and after(nxt) every 'o', then the answer would be the sum of ( ( prev — 1 ) * ( nxt — 1 ) ).

for example : "vvvovvv" -> nxt = prev = 3 -> ans = 2 * 2 = 4

So can anyone help me to know where I did the mistake ??

Here is my code :

#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main () 
{
    
    string s ;
    cin >> s ;
    
    int ctr = 0 ;
    for ( int i = 0 ; i < s.length() ; i ++ )
        if ( s[i] == 'v' )
            ctr ++ ;
    
    ll ans = 0 ;
    ll prev = 0 ;
    ll nxt = ctr ;
    
    for ( int i = 0 ; i < s.length() ; i ++ )
    {
        if ( s[i] == 'o' && prev && nxt )
            ans += ( prev - 1 ) * ( nxt - 1 ) ;
        
        else
        {
            prev ++ ;
            nxt -- ;
        }
    }
    
    cout << ans ;
}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it