• WOW Factor


    Recall that string aa is a subsequence of a string bb if aa can be obtained from bb by deletion of several (possibly zero or all) characters. For example, for the string aa="wowwo", the following strings are subsequences: "wowwo", "wowo", "oo", "wow", "", and others, but the following are not subsequences: "owoo", "owwwo", "ooo".

    The wow factor of a string is the number of its subsequences equal to the word "wow". Bob wants to write a string that has a large wow factor. However, the "w" key on his keyboard is broken, so he types two "v"s instead.

    Little did he realise that he may have introduced more "w"s than he thought. Consider for instance the string "ww". Bob would type it as "vvvv", but this string actually contains three occurrences of "w":

    • "vvvv"
    • "vvvv"
    • "vvvv"

    For example, the wow factor of the word "vvvovvv" equals to four because there are four wows:

    • "vvvovvv"
    • "vvvovvv"
    • "vvvovvv"
    • "vvvovvv"

    Note that the subsequence "vvvovvv" does not count towards the wow factor, as the "v"s have to be consecutive.

    For a given string ss, compute and output its wow factor. Note that it is not guaranteed that it is possible to get ss from another string replacing "w" with "vv". For example, ss can be equal to "vov".

    Input

    The input contains a single non-empty string ss, consisting only of characters "v" and "o". The length of ss is at most 106106.

    Output

    Output a single integer, the wow factor of ss.

    Examples
    input
    Copy
    vvvovvv
    
    output
    Copy
    4
    
    input
    Copy
    vvovooovovvovoovoovvvvovovvvov
    
    output
    Copy
    100
    
    Note

    The first example is explained in the legend.


    刚开始忘了两个int相加还是int,只用了一个longlong的sum,导致溢出。

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <unordered_set>
    #include <unordered_map>
    #include <xfunctional>
    #define ll long long
    #define mod 998244353
    using namespace std;
    int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };
    const int maxn = 1e5 + 5;
    const long long inf = 0x7f7f7f7f7f7f7f7f;
    
    int main()
    {
        string s;
        cin >> s;
        int v = 0, maxn = 0, initial = 0, firsto = 0;
        vector<ll> dp;
        for (int i = 0; s[i] == 'v'; i++)
            initial++;
        if (initial > 0)
            dp.push_back(initial - 1);
        else
            dp.push_back(0);
        for (int i = initial+1; i < s.size(); i++)
        {
            if (s[i] == 'v')
                maxn++;
            else
            {
                if (maxn > 1)
                    dp.push_back(dp.back() + maxn - 1);
                else
                    dp.push_back(dp.back());
                maxn = 0;
            }
            if (i == s.size() - 1 && maxn>1)
            {
                dp.push_back(dp.back() + maxn - 1);
            }
                
        }
    
        ll sum = 0;
        for (int i = 0; i < dp.size(); i++)
        {
            sum += (dp.back() - dp[i])*dp[i];
        }
        cout << sum;
        return 0;
    }
  • 相关阅读:
    Codeforces Round #161 (Div. 2)
    Codeforces Round #160 (Div. 2)
    Codeforces Round #159 (Div. 2)
    Codeforces Round #157 (Div. 2)
    世界树的考验「NOIP多校联考 2019」
    最大异或和
    腿部挂件「NOIP多校联考 2019」
    玩具取名「HAOI2008」
    涂色「CQOI2007」
    唱、跳、rap 和篮球「TJOI2019」
  • 原文地址:https://www.cnblogs.com/dealer/p/12345905.html
Copyright © 2020-2023  润新知