oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

alphabrackets Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

alphabrackets.html

Problem Description

An valid alphabracket string consists of a series of upper and lowercase letters, and must be in the form of:

  • an empty string,
  • A#a where A represents an uppercase letter, a represents a lowercase version of the same letter, and # represents a valid alphabracket string, or
  • #@, where # and @ are two valid alphabracket strings.

For example, BAaCcb is a valid alphabracket string while ABab is not.

Given a string S consisting of only uppercase and lowercase letters, determine how many non-empty substrings of S are valid alphabracket strings.

Input

The first and only line of input will contain one string, S.

Output

The output should contain one integer, the number of non-empty substrings of S which are valid alphabracket strings.

Limits

Subtask 1 (16%): 1 ≤ length of string ≤ 300.

Subtask 2 (18%): 1 ≤ length of string ≤ 2000.

Subtask 3 (14%): 1 ≤ length of string ≤ 100000, the string will only consist of 'A' and 'a', and all 'A's will come before any 'a'.

Subtask 4 (23%): 1 ≤ length of string ≤ 100000, the string will only consist of 'A' and 'a'.

Subtask 5 (13%): 1 ≤ length of string ≤ 100000.

Subtask 6 (16%): 1 ≤ length of string ≤ 2000000.

Subtask 7 (0%): Sample Testcases.

Sample Input 1

BAaCcb

Sample Output 1

4

Sample Input 2

ABab

Sample Output 2

0

Sample Input 3

aAaAa

Sample Output 3

3

Tags

Dynamic Programming

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
116240.5s256MBMinimum
218450.5s256MBMinimum
314200.5s256MBMinimum
423240.5s256MBMinimum
5131060.5s256MBMinimum
6161270.5s256MBMinimum
7030.5s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o alphabrackets -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.