D. 游程回文计数
游程回文计数
春招模拟赛第十场|协程|2023.04.15研发岗笔试
- Status
- Done
- Rule
- IOI
- Problem
- 4
- Start at
- 2023-4-24 19:00
- End at
- 2023-4-24 21:00
- Duration
- 2 hour(s)
- Host
- Partic.
- 41
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
全相同的一段内部所有子串都是回文,贡献 a(a+1)/2。相邻两段字符不同,偶回文无法跨段。跨至少三段的奇回文:取奇数段 i..j(j−i 为偶数),中间段的长度序列成回文时,两端各取 x=1..min(ai,aj) 个字符,贡献 min(ai,aj)。
时间复杂度 O(n2),空间复杂度 O(n)。
磁盘上的比特流被压成 n 段交替游程:第 1 段是 a1 个 1,第 2 段是 a2 个 0,第 3 段又是 1,依此类推。完整性校验需要统计该比特流中非空回文子串的个数。答案可能很大,请对 1000000007 取模。
回文指正着读和倒着读相同;子串指连续一段。
约束:1≤n≤103,1≤ai≤1000000000。
第一行一个正整数 n。 第二行 n 个正整数 ai。
输出回文子串个数对 1000000007 取模的结果。
输入
3
3 1 3
输出
16
说明
按题意模拟计算得到。
输入
1
5
输出
15
说明
按题意模拟计算得到。
输入
5
1 1 1 1 1
输出
9
说明
按题意模拟计算得到。
Scan the QR code below with WeChat to sign in
First-time scan will create your account automatically
请使用微信扫描下方二维码完成注册