[AtCoder - 5659]> <(thinking title)

><

Write directly to the Chinese

Problem Statement

Given a string of length S. S N-1 in each character <or>.

When all i (1≤i≤N-1) satisfies the following condition, N nonnegative integers a1, a2, [cdots], aN sequence is considered to be satisfied

  • If Si = <: ai <ai + 1
  • If Si =>: ai> ai + 1

N elements find the minimum non-negative integer and may be a good sequence.

Restrictions

  • 2≤N≤5×105
  • S is a string of N-1 by the <and> Composition

Input

Input from the standard input, the following format:

S

Output

N elements find the minimum non-negative integer and may be a good sequence.

Sample Input 1

<>>

Sample Output 1

3

a = (0,2,1,0) is a good sequence, the sum of which is 3. Not a good sequence, which sum is less than 3

Sample Input 2

<>>><<><<<<<>>><

Sample Output 2

28

Topic links:
https://vjudge.net/problem/AtCoder-5659

 

Not difficult to find to find the "<>" This can

"<>" Is set to the number of left and right sides of l, r; large as a maxn, is a small minn, and both sides of the (maxn + 1) / 2 * maxn + (minn + 1) / 2 * minn -minn

"> <" Is defined as the number of left and right sides l, r; and to both sides of the (l + 1) / 2 * l + (r + 1) / 2 * r

S can be traversed again so long, get "<>" Further discussions, other circumstances Suppose there are n "<" or ">", then ans + = (n + 1) / 2 * n;

AC Code

#include <bits / STDC ++. H>
 #define Mod 1000000007
 #define EPS-1E. 6
 #define LL Long Long
 #define INF 0x3f3f3f3f
 #define MEM (X, Y) Memset (X, Y, the sizeof (X))
 #define MAXN 10 + 1000000000000
 the using  namespace STD;
 String S; 
LL len; 
LL ANS; 
void Solve (start LL, LL sum, LL in Flag) // search start position, the sum total of a consecutive <or>, the last time there occurs <> 
{ 
    LL I; 
    LL F = 0 ; 
    LL CNT = . 1 ; // count 
    char R & lt = s[start];
    for (i = start + 1; i < len; i++)
    {
        if (s[i] == r)
            cnt++;
        else
        {
            if (r == '<' && s[i] == '>') //存在<>,f=1
                f = 1;
            break;
        }
    }
    if (flag == 1)
    {
        if (cnt > sum)
        {
            if (cnt > 1) 
            { 
                Years + = (cnt + 1 ) * cnt / 2 ; 
                years - = Sum; 
            } 
            Else 
            { 
                years + = 1 ; 
                years - = Sum; 
            } 
        } 
        Else 
        { 
            if (cnt> 1 ) 
            { 
                years + = (cnt + 1 ) * cnt / 2 ; 
                years - = cnt; 
            } 
            else
            { 
                ANS + = . 1 ; 
                ANS - = CNT; 
            } 
        } 
        IF (I> = len) // traverse the complete 
            return ;
         return Solve (I, CNT, F); 
    } 
    the else 
    { 
        IF (CNT> . 1 ) 
            ANS + = (CNT + . 1 ) * CNT / 2 ;
         the else 
        { 
            ANS + = . 1 ; 
        } 
        IF (I> = len) // traverse the complete 
            return;
        return solve(i, cnt, f);
    }
}
int main()
{
    ans = 0;
    cin >> s;
    len = s.size();
    solve(0, 0, 0);
    cout << ans << endl;
}

 

Guess you like

Origin www.cnblogs.com/sky-stars/p/11824801.html