#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<ll>mn,mx;
ll dp[20][11][11][2][2];
ll rec(int idx, int p, int pp, bool b, bool s){
if(idx == n){
return 1;
}
if(dp[idx][p + 1][pp + 1][b][s] != -1)
return dp[idx][p + 1][pp + 1][b][s];
int i = b ? 0 : mn[idx];
int j = s ? 9 : mx[idx];
ll ret = 0;
for(int d = i; d <= j; d++){
if(d != p && d != pp)
ret += rec(idx + 1, d, p, b || (d > mn[idx]), s || (d < mx[idx]));
}
return dp[idx][p + 1][pp + 1][b][s] = ret;
}
int len(ll x){
int ret = 0;
while(x){
x/=10;
ret++;
}
return ret;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll a,b;
cin>>a>>b;
int len_a=len(a),len_b=len(b);
ll ans = 0;
for(n = len_a; n <= len_b; ++n){
memset(dp, -1, sizeof(dp));
if(n != len_a){
mn.push_back(1);
for(int i = 1; i < n; i++)mn.push_back(0);
}else{
string st = to_string(a);
for(auto ch : st)mn.push_back(ch-'0');
}
if(n != len_b){
for(int i = 1; i < n; i++)mx.push_back(9);
}else{
string st = to_string(b);
for(auto ch : st)mx.push_back(ch - '0');
}
ans += rec(0, -1, -1, 0, 0);
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
5 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
6 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
8 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
15 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
16 |
Correct |
1 ms |
328 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
356 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
328 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
328 KB |
Output is correct |
44 |
Correct |
1 ms |
328 KB |
Output is correct |
45 |
Correct |
0 ms |
328 KB |
Output is correct |