#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef stack<int> si;
typedef queue<int> qi;
typedef deque<int> di;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define endl '\n'
#define pb push_back
#define FOR(i,g,b) for(int i = g; i <= b; i++)
#define BACK(i,g,b) for(int i = g; i >= b; i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define gcd __gcd
#define setmin(x,y) x=min((x),(y))
#define setmax(x,y) x=max((x),(y))
const int MAXN=(1e6)+5;
const int inf=1e18;
const int MOD=1e9+7;
int dp[20][11][11][2][2],a,b;
vi dig;
int bt(int idx,int p1,int p2,bool k1,bool k2)
{
if(idx==(int)(dig.size())) return 1;
if(~dp[idx][p1][p2][k1][k2]) return dp[idx][p1][p2][k1][k2];
int res=0;
FOR(i,0,(k1?9:dig[idx])) if(i!=p1&&i!=p2) res+=bt(idx+1,p2,(!i&&!k2?10:i),k1|(i<dig[idx]),k2|(i>0));
return dp[idx][p1][p1][k1][k2]=res;
}
int solve(int x)
{
memset(dp,-1,sizeof dp);
dig.clear();
while(x) {dig.pb(x%10); x/=10;}
reverse(dig.begin(),dig.end());
return bt(0,10,10,0,0);
}
signed main()
{
fastIO
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
cin>>a>>b;
cout<<solve(b)-solve(a-1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Execution timed out |
1076 ms |
340 KB |
Time limit exceeded |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Execution timed out |
1074 ms |
340 KB |
Time limit exceeded |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
284 ms |
368 KB |
Output is correct |
2 |
Execution timed out |
1089 ms |
340 KB |
Time limit exceeded |
3 |
Execution timed out |
1080 ms |
340 KB |
Time limit exceeded |
4 |
Execution timed out |
1081 ms |
340 KB |
Time limit exceeded |
5 |
Correct |
99 ms |
368 KB |
Output is correct |
6 |
Correct |
383 ms |
340 KB |
Output is correct |
7 |
Correct |
6 ms |
388 KB |
Output is correct |
8 |
Correct |
4 ms |
340 KB |
Output is correct |
9 |
Correct |
8 ms |
340 KB |
Output is correct |
10 |
Correct |
10 ms |
340 KB |
Output is correct |
11 |
Correct |
286 ms |
368 KB |
Output is correct |
12 |
Correct |
58 ms |
340 KB |
Output is correct |
13 |
Correct |
15 ms |
340 KB |
Output is correct |
14 |
Correct |
105 ms |
372 KB |
Output is correct |
15 |
Correct |
114 ms |
372 KB |
Output is correct |
16 |
Execution timed out |
1089 ms |
340 KB |
Time limit exceeded |
17 |
Execution timed out |
1066 ms |
340 KB |
Time limit exceeded |
18 |
Execution timed out |
1065 ms |
340 KB |
Time limit exceeded |
19 |
Execution timed out |
1077 ms |
340 KB |
Time limit exceeded |
20 |
Execution timed out |
1082 ms |
340 KB |
Time limit exceeded |
21 |
Execution timed out |
1043 ms |
340 KB |
Time limit exceeded |
22 |
Execution timed out |
1078 ms |
340 KB |
Time limit exceeded |
23 |
Execution timed out |
1090 ms |
340 KB |
Time limit exceeded |
24 |
Execution timed out |
1079 ms |
340 KB |
Time limit exceeded |
25 |
Execution timed out |
1078 ms |
340 KB |
Time limit exceeded |
26 |
Execution timed out |
1079 ms |
340 KB |
Time limit exceeded |
27 |
Execution timed out |
1078 ms |
340 KB |
Time limit exceeded |
28 |
Execution timed out |
1078 ms |
340 KB |
Time limit exceeded |
29 |
Execution timed out |
1089 ms |
340 KB |
Time limit exceeded |
30 |
Execution timed out |
1077 ms |
340 KB |
Time limit exceeded |
31 |
Execution timed out |
1082 ms |
340 KB |
Time limit exceeded |
32 |
Execution timed out |
1087 ms |
340 KB |
Time limit exceeded |
33 |
Execution timed out |
1078 ms |
340 KB |
Time limit exceeded |
34 |
Execution timed out |
1076 ms |
340 KB |
Time limit exceeded |
35 |
Execution timed out |
1086 ms |
340 KB |
Time limit exceeded |
36 |
Execution timed out |
1083 ms |
340 KB |
Time limit exceeded |
37 |
Execution timed out |
1082 ms |
340 KB |
Time limit exceeded |
38 |
Execution timed out |
1066 ms |
340 KB |
Time limit exceeded |
39 |
Execution timed out |
1081 ms |
340 KB |
Time limit exceeded |
40 |
Execution timed out |
1074 ms |
340 KB |
Time limit exceeded |
41 |
Execution timed out |
1074 ms |
340 KB |
Time limit exceeded |
42 |
Execution timed out |
1058 ms |
340 KB |
Time limit exceeded |
43 |
Execution timed out |
1061 ms |
340 KB |
Time limit exceeded |
44 |
Execution timed out |
1085 ms |
340 KB |
Time limit exceeded |
45 |
Execution timed out |
1077 ms |
340 KB |
Time limit exceeded |