//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
//#pragma expected_value
//#pragma isolated_call
//#pragma disjoint
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define setpre(i) setprecision(i)<<fixed
#define foru(i, a, b) for(int i=a;i<=b;++i)
#define ford(i, a, b) for(int i=a;i>=b;--i)
#define mp make_pair
#define moo cout<<"moo "
#define fi first
#define se second
ll lmod = 1e9 + 7;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int, int> ii;
typedef pair<double, double> dd;
ll dp[20][2][2][11][11];
string num;
ll solve(int pos, bool under, bool started, int dig1, int dig2){
ll &ans = dp[pos][under][started][dig1][dig2];
if(pos == num.size()){
if(!started) return 0;
else return 1;
}
if(ans != -1) return ans;
ans = 0;
foru(i, 0, 9){
if(!under and i > num[pos] - '0') break;
if(i == dig1 or i == dig2) continue;
if(i) ans += solve(pos + 1, under or i < num[pos] - '0', 1, dig2, i);
else ans += solve(pos + 1, under or i < num[pos] - '0', started, dig2, i);
}
return ans;
}
ll cnt(int x, int y){
num = to_string(y);
memset(dp, -1, sizeof dp);
int temp1 = solve(0, 0, 0, 10, 10);
// cout << temp1 << endl;
num = to_string(x - 1);
memset(dp, -1, sizeof dp);
int temp2 = solve(0, 0, 0, 10, 10);
// cout << temp2 << endl;
return temp1 - temp2;
}
int main(){
// freopen("input.inp", "r", stdin);
// freopen("output.out", "w", stdout);
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// cout << cnt(1, 10);
ll a, b; cin >> a >> b;
cout << cnt(a, b) << endl;
// fclose(stdout);
}
Compilation message
numbers.cpp: In function 'long long int solve(int, bool, bool, int, int)':
numbers.cpp:33:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | if(pos == num.size()){
| ~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is 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 |
1 ms |
340 KB |
Output is correct |
18 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
320 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 |
320 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 |
0 ms |
320 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
292 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 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
20 |
Correct |
0 ms |
320 KB |
Output is correct |
21 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
23 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
33 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
34 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
35 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
36 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
37 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
38 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
39 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
40 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
41 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Incorrect |
0 ms |
328 KB |
Output isn't correct |
44 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
45 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |