#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
int dp[20][12][12][2];
int f(string s,int indx,int x,int y,int ok){
if(indx == s.size())
return 1;
int &cur = dp[indx][x][y][ok];
if(cur != -1)
return cur;
int fi = (indx == 0),se;
if(ok) se = 9;
else se = s[indx]-'0';
for(int i=fi;i<=se;i++){
if(i == x || i == y) continue;
cur += f(s,indx+1,y,i,(ok||i<s[indx]-'0'));
}
return cur+=1;
}
void solve(){
int a,b;
cin >> a >> b;
memset(dp,-1,sizeof(dp));
string tmp = to_string(a-1);
int res = f(tmp,0,10,10,0);
for(int i=2;i<tmp.size();i++){
res += 81*pow(8,i-2);
}
memset(dp,-1,sizeof(dp));
tmp = to_string(b);
for(int i=2;i<tmp.size();i++){
res -= 81*pow(8,i-2);
}
cout << f(tmp,0,10,10,0) - res << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
for(int i=1;i<=t;i++){
solve();
}
return 0;
}
Compilation message
numbers.cpp: In function 'long long int f(std::string, long long int, long long int, long long int, long long int)':
numbers.cpp:16:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | if(indx == s.size())
| ~~~~~^~~~~~~~~~~
numbers.cpp: In function 'void solve()':
numbers.cpp:44:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=2;i<tmp.size();i++){
| ~^~~~~~~~~~~
numbers.cpp:51:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i=2;i<tmp.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
292 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
232 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
312 KB |
Output is correct |
27 |
Correct |
1 ms |
316 KB |
Output is correct |
28 |
Correct |
2 ms |
324 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
292 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
320 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
312 KB |
Output is correct |
35 |
Correct |
1 ms |
356 KB |
Output is correct |
36 |
Correct |
1 ms |
312 KB |
Output is correct |
37 |
Correct |
1 ms |
304 KB |
Output is correct |
38 |
Correct |
2 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
316 KB |
Output is correct |
40 |
Correct |
1 ms |
296 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |