CF963A.Alternating Sum
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two integers a and b. Moreover, you are given a sequence s0,s1,…,sn. All values in s are integers 1 or −1. It's known that sequence is k-periodic and k divides n+1. In other words, for each k≤i≤n it's satisfied that si=si−k.
Find out the non-negative remainder of division of i=0∑nsian−ibi by 109+9.
Note that the modulo is unusual!
给你两个整数 a 和 b。此外,你被给定一个序列 s0,s1,…,sn。序列 s 中所有值均为整数 1 或 −1。已知该序列是 k-周期性的,且 k 整除 n+1。换言之,对每个满足 k≤i≤n 的 i,均有 si=si−k。
求 i=0∑nsian−ibi 除以 109+9 所得的非负余数。
注意:此处取模的模数是非同寻常的!
输入格式
The first line contains four integers n,a,b and k (1≤n≤109,1≤a,b≤109,1≤k≤105).
The second line contains a sequence of length k consisting of characters '+' and '-'.
If the i-th character (0-indexed) is '+', then si=1, otherwise si=−1.
Note that only the first k members of the sequence are given, the rest can be obtained using the periodicity property.
第一行包含四个整数 n,a,b 和 k (1≤n≤109,1≤a,b≤109,1≤k≤105)。
第二行包含一个长度为 k 的字符串,由字符 '+' 和 '-' 组成。
若第 i 个字符(从 0 开始编号)为 '+',则 si=1;否则 si=−1。
注意:仅给出序列的前 k 项,其余项可利用周期性性质得到。
输出格式
Output a single integer — value of given expression modulo 109+9.
输出一个整数——给定表达式的值对 109+9 取模的结果。
输入输出样例
输入#1
2 2 3 3 +-+
输出#1
7
输入#2
4 1 5 1 -
输出#2
999999228
说明/提示
In the first example:
(i=0∑nsian−ibi) = 2230−2131+2032 = 7
In the second example:
(i=0∑nsian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9).
在第一个例子中:
(i=0∑nsian−ibi) = 2230−2131+2032 = 7
在第二个例子中:
(i=0∑nsian−ibi)=−1450−1351−1252−1153−1054=−781≡999999228(mod109+9)。
输入解题思路,AI测评打分。不知道怎么写?