#include <iostream>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <queue>
#include <stack>
#include <time.h>
#include <map>
#include <algorithm>
#include <iomanip>
#define int long long
#define BIT(x,pos) (((x)>>(pos)) & 1LL)
#define _(x) (1LL<<(x))
#define cnt_bit(x) __builtin_popcountll(x)
#define turn_on(x,pos) ((x) |= (_(pos)))
#define turn_off(x,pos) ((x) &= ~(_(pos))
#define flip_bit(x,pos) ((x) ^= (_(pos))
#define low_bit(x) ((x) & (-x))
#define bit_on(x) (_(x)-1LL)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef int64_t int64;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;
typedef vector<ll> vll;
ll f[20][11][11][3][3];
ll a,b;
string convert_string(ll n)
{
string res = "";
for (;n > 0; n /= 10)
{
char tmp = (char)(n % 10 + '0');
res = tmp + res;
}
return res;
}
int get_digit(const string &s,int pos)
{
return s[pos-1] - '0';
}
int get_len(const string &s)
{
return s.size();
}
ll calc(int pos,int first_D,int second_D,bool is_less,bool not_first,int len,const string &s)
{
if (pos > len)
{
if (not_first == true) return 1;
else return 0;
}
ll &ret = f[pos][first_D][second_D][is_less][not_first];
if (ret != -1) return ret;
ret = 0;
int x = 9;
if (is_less == false) x = get_digit(s,pos);
for (int d = 0; d <= x; ++d)
if (d != first_D && d != second_D)
{
int t_firstD = second_D;
int t_secondD = d;
bool new_notfirst = (not_first | (d > 0));
if (not_first == false && d == 0) t_secondD = 10;
ret += calc(pos+1,t_firstD,t_secondD,is_less | (d < x),new_notfirst,len,s);
}
return ret;
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(nullptr);
cin>>a>>b;
memset(f,-1,sizeof(f));
string sa = convert_string(a-1);
int len = get_len(sa);
ll res_a = calc(1,10,10,0,0,len,sa);
memset(f,-1,sizeof(f));
string sb = convert_string(b);
len = get_len(sb);
ll res_b = calc(1,10,10,0,0,len,sb);
cout<<res_b - res_a;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
620 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
492 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
512 KB |
Output is correct |
33 |
Correct |
1 ms |
492 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 ms |
492 KB |
Output is correct |
39 |
Correct |
1 ms |
492 KB |
Output is correct |
40 |
Correct |
1 ms |
492 KB |
Output is correct |
41 |
Correct |
1 ms |
492 KB |
Output is correct |
42 |
Correct |
1 ms |
492 KB |
Output is correct |
43 |
Correct |
1 ms |
492 KB |
Output is correct |
44 |
Correct |
1 ms |
492 KB |
Output is correct |
45 |
Correct |
1 ms |
492 KB |
Output is correct |