CF963A.Alternating Sum
普及/提高-
通过率:0%
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!
输入格式
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.
输出格式
Output a single integer — value of given expression modulo 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) .