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 ;
}
vovovov -> ans is 0, and your program gives 1. "v" letters may not be consecutive and then x letters 'v' does not have to give x-1 letters 'w'.