Connection Status:
Competition Arena > SquareScoresDiv2
SRM 654 · 2015-01-29 · by sigma425 · Brute Force
Class Name: SquareScoresDiv2
Return Type: int
Method Name: getscore
Arg Types: (string)
Problem Statement

Problem Statement

A substring of a string is a contiguous sequence of characters from the string. For example, each of the strings "ab", "bcd", and "e" is a substring of "abcde". On the other hand, "cba", "ace", and "f" are not substrings of "abcde".

The score of a string S is the number of ways in which we can select a non-empty substring of S such that all characters in the substring are the same. If two substrings consist of the same letters but occur at different places in S, they are still considered different. For example, the score of "aaaba" is 8: there are four occurrences of the substring "a", two occurrences of "aa", one occurrence of "aaa", and one of "b".

On her birthday, Maki got a String s from her friend Niko as a present. Calculate and return its score.

Constraints

  • The length of s will be between 1 and 100, inclusive.
  • Each character in s will be a lowercase letter ('a'-'z').
Examples
0)
"aaaba"
Returns: 8

The example explained above.

1)
"zzzxxzz"
Returns: 12
2)
"abcdefghijklmnopqrstuvwxyz"
Returns: 26
3)
"p"
Returns: 1
4)
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
Returns: 5050

All substrings satisfy the condition.

Submissions are judged against all 82 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class SquareScoresDiv2 with a public method int getscore(string s) · 82 test cases · 2 s / 256 MB per case

Submitting as anonymous