-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicpc10802.cpp
More file actions
46 lines (42 loc) · 1.1 KB
/
icpc10802.cpp
File metadata and controls
46 lines (42 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <string>
using namespace std;
const int MOD = 20150523;
int toNumber(char c){
return c - '0';
}
int countClap(string num){
int dp[2][3] = { 0 }, s = 0, clap = 0, t = 0;
int mod3[3] = {1, 3, 3};
bool flag;
for(int idx = 0; idx < num.size(); idx++, t = 1 - t){
int n = toNumber(num[idx]);
for(int i = 0; i < 3; i++)
dp[t][i] = 0;
for(int i = 0; i < 3; i++){
clap = (clap + dp[1 - t][i] * 3) % MOD;
for(int j = 0; j < 3; j++)
dp[t][(i + j) % 3] = (dp[t][(i + j) % 3] + dp[1 - t][i] * mod3[j]) % MOD;
}
for(int k = 0; k < n; k++)
if(k && k % 3 == 0) clap++;
else dp[1 - t][(s + k) % 3]++;
if(bool)
s = (s + n) % 3;
}
if(!s) clap++;
return (clap + dp[1 - t][0]) % MOD;
}
int main(){
string a, b;
int answer;
cin >> a >> b;
(*a.rbegin())--;
for(auto it = a.rbegin(); *it < '0';){
(*it) = '9';
(*++it)--;
}
answer = (countClap(b) - countClap(a)) % MOD;
cout << answer << endl;
return 0;
}