zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    CSP-S2019 括号树
    [CQOI2007]余数求和
    CF1000E We Need More Bosses
    [HAOI2009]毛毛虫
    ls命令
    HTML的标签 属性 等等
    虚拟机安装Tools
    1.1 什么是安全渗透
    004-Kali Linux安装-熟悉环境
    003-Kali Linux 安装-持久加密USB安装、熟悉环境、熟悉BASH命令
  • 原文地址:https://www.cnblogs.com/dealer/p/12345905.html
Copyright © 2011-2022 走看看