#include<bits/stdc++.h> //:3
using namespace std;
typedef long long LL;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
#define int long long
/*
#define cin in
#define cout out
ifstream in(".in");
ofstream out(".out");
*/
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const LL inf = 2e9;
const LL mod = 1e9 + 7;
const int N = 2e2 + 11;
const LL INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
int n, dp[30][30][30][2][2][2], a[30];
int get(string s1, string s2){
memset(dp, 0, sizeof(dp));
int dif = sz(s2) - sz(s1);
for(int i = 1; i <= dif; i++)a[i] = 1;
n = sz(s2);
while(sz(s1) < sz(s2))s1 = '0' + s1;
s1 = '.' + s1;
s2 = '.' + s2;
dp[0][0][0][0][0][1] = 1;
int ans = 0;
for(int i = 1; i <= n; i++){
int x = s1[i] - '0', y = s2[i] - '0';
for(int smaller = 0; smaller <= 1; smaller++){
for(int bigger = 0; bigger <= 1; bigger++){
for(int all_zero = 0; all_zero <= 1; all_zero++){
for(int A = 0; A <= 9; A++){
for(int B = 0; B <= 9; B++){
for(int C = 0; C <= 9; C++){
if(!smaller && C > y)continue;
if(!bigger && C < x)continue;
int all_zero1 = all_zero;
if(B != 0)all_zero1 = 0;
if((i >= 2) && (B == C) && !(a[i - 1] && all_zero1))continue;
if((i >= 3) && (A == B) && !(a[i - 1] && all_zero1))continue;
if((i >= 3) && (A == C) && !(a[i - 2] && all_zero))continue;
int smaller1 = smaller, bigger1 = bigger;
if(C < y)smaller1 = 1;
if(C > x)bigger1 = 1;
dp[i][B][C][smaller1][bigger1][all_zero1] += dp[i - 1][A][B][smaller][bigger][all_zero];
}
}
}
}
}
}
}
for(int A = 0; A <= 9; A++){
for(int B = 0; B <= 9; B++){
for(int smaller = 0; smaller <= 1; smaller++){
for(int bigger = 0; bigger <= 1; bigger++){
for(int all_zero = 0; all_zero <= 1; all_zero++){
ans += dp[n][A][B][smaller][bigger][all_zero];
}
}
}
}
}
return ans;
}
void solve(){
string s1, s2;
cin >> s1 >> s2;
int ans = get(s1, s2);
cout << ans << '\n';
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
//cout << setptecision(6) << fixed;
int T = 1;
//cin >> T;
while(T--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2028 KB |
Output is correct |
2 |
Correct |
2 ms |
2028 KB |
Output is correct |
3 |
Correct |
2 ms |
2028 KB |
Output is correct |
4 |
Correct |
2 ms |
2028 KB |
Output is correct |
5 |
Correct |
1 ms |
2028 KB |
Output is correct |
6 |
Correct |
2 ms |
2028 KB |
Output is correct |
7 |
Correct |
2 ms |
2028 KB |
Output is correct |
8 |
Correct |
2 ms |
2028 KB |
Output is correct |
9 |
Correct |
1 ms |
2028 KB |
Output is correct |
10 |
Correct |
1 ms |
2028 KB |
Output is correct |
11 |
Correct |
2 ms |
2028 KB |
Output is correct |
12 |
Correct |
3 ms |
2028 KB |
Output is correct |
13 |
Correct |
1 ms |
2028 KB |
Output is correct |
14 |
Correct |
2 ms |
2028 KB |
Output is correct |
15 |
Correct |
2 ms |
2028 KB |
Output is correct |
16 |
Correct |
2 ms |
2028 KB |
Output is correct |
17 |
Correct |
2 ms |
2028 KB |
Output is correct |
18 |
Correct |
2 ms |
2028 KB |
Output is correct |
19 |
Correct |
2 ms |
2028 KB |
Output is correct |
20 |
Correct |
2 ms |
2028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2028 KB |
Output is correct |
2 |
Correct |
2 ms |
2028 KB |
Output is correct |
3 |
Correct |
2 ms |
2028 KB |
Output is correct |
4 |
Correct |
2 ms |
2028 KB |
Output is correct |
5 |
Correct |
2 ms |
2028 KB |
Output is correct |
6 |
Correct |
2 ms |
2028 KB |
Output is correct |
7 |
Correct |
2 ms |
2028 KB |
Output is correct |
8 |
Correct |
2 ms |
2028 KB |
Output is correct |
9 |
Correct |
2 ms |
2028 KB |
Output is correct |
10 |
Correct |
2 ms |
2028 KB |
Output is correct |
11 |
Correct |
2 ms |
2028 KB |
Output is correct |
12 |
Correct |
2 ms |
2028 KB |
Output is correct |
13 |
Correct |
2 ms |
2028 KB |
Output is correct |
14 |
Correct |
2 ms |
2028 KB |
Output is correct |
15 |
Correct |
2 ms |
2028 KB |
Output is correct |
16 |
Correct |
2 ms |
2028 KB |
Output is correct |
17 |
Correct |
2 ms |
2028 KB |
Output is correct |
18 |
Correct |
2 ms |
2028 KB |
Output is correct |
19 |
Correct |
2 ms |
2028 KB |
Output is correct |
20 |
Correct |
2 ms |
2028 KB |
Output is correct |
21 |
Correct |
2 ms |
2028 KB |
Output is correct |
22 |
Correct |
2 ms |
2028 KB |
Output is correct |
23 |
Correct |
2 ms |
2028 KB |
Output is correct |
24 |
Correct |
2 ms |
2028 KB |
Output is correct |
25 |
Correct |
2 ms |
2028 KB |
Output is correct |
26 |
Correct |
2 ms |
2028 KB |
Output is correct |
27 |
Correct |
3 ms |
2028 KB |
Output is correct |
28 |
Correct |
2 ms |
2028 KB |
Output is correct |
29 |
Correct |
2 ms |
2028 KB |
Output is correct |
30 |
Correct |
2 ms |
2048 KB |
Output is correct |
31 |
Correct |
2 ms |
2028 KB |
Output is correct |
32 |
Correct |
2 ms |
2028 KB |
Output is correct |
33 |
Correct |
2 ms |
2028 KB |
Output is correct |
34 |
Correct |
2 ms |
2028 KB |
Output is correct |
35 |
Correct |
2 ms |
2028 KB |
Output is correct |
36 |
Correct |
2 ms |
2028 KB |
Output is correct |
37 |
Correct |
2 ms |
2028 KB |
Output is correct |
38 |
Correct |
2 ms |
2028 KB |
Output is correct |
39 |
Correct |
2 ms |
2028 KB |
Output is correct |
40 |
Correct |
2 ms |
2028 KB |
Output is correct |
41 |
Correct |
2 ms |
2028 KB |
Output is correct |
42 |
Correct |
2 ms |
2028 KB |
Output is correct |
43 |
Correct |
2 ms |
2028 KB |
Output is correct |
44 |
Correct |
2 ms |
2028 KB |
Output is correct |
45 |
Correct |
2 ms |
2028 KB |
Output is correct |