cswork / OA打开练习工作台

WayfairOA #2

Number of Divisible Substrings (For MLE)

估计中等可在线判题

考点(AI 标注)前缀和区间哈希计数

Map lowercase letters using this fixed table: ab→1, cde→2, fgh→3, ijk→4, lmn→5, opq→6, rst→7, uvw→8, xyz→9. Count the contiguous non-empty substrings whose sum of mapped values is divisible by the substring length. Count by position: identical content at different positions is counted separately. The mapping image in the fixed original text was a broken local path; this site restored it from the public Problem Source original image on the original FastPrep page, and the original starter also explicitly references LC2950; the evidence and image hash are in the editorial.

输入格式

A lowercase English string word, without quotes. Full original range 1≤word.length≤2000; the empty string is not accepted.

输出格式

Output the number of qualifying contiguous non-empty substrings, as an exact integer with no modulo.

样例 1

输入:

asdf

输出:

6

样例 2

输入:

bdh

输出:

4

样例 3

输入:

abcd

输出:

6

样例说明

Original examples kept: asdf→6, corresponding to a, s, d, f, as, sdf; bdh→4, corresponding to b, d, h, bdh; abcd→6, corresponding to a, b, c, d, ab, cd. The first group ab has only two letters, so you cannot map by three letters per group or by a phone keypad.