#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[19][11][11][2]={};
int len;
int ar[19];
ll DP(int pos,int m1,int m2,int sm) {
ll &ret=dp[pos][m1+1][m2+1][sm];
if(len==pos) {
ret=1;
return 1;
}
ret=0;
int mx=sm?9:ar[pos];
for(int i=0;i<mx;i++) {
if(i!=m1&&i!=m2)
ret+=DP(pos+1,m2,i,1);
}
if(mx!=m2 && mx!=m1)
ret+=DP(pos+1,m2,mx,sm);
return ret;
}
ll calc(ll a) {
if(a<=9)return a+1;
memset(dp,-1,sizeof dp);
len=0;
while(a) {
ar[len++]=a%10;
a/=10;
}
reverse(ar,ar+len);
ll res=DP(0,0,-1,0);
for(int i=1;i<=len;i++)res+=DP(i,0,-1,1);
return res;
}
int main() {
ll a,b;
cin>>a>>b;
if(a<b)
swap(a,b);
ll pd=calc(a)-calc(b-1);
cout<<pd<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Execution timed out |
1095 ms |
384 KB |
Time limit exceeded |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
14 ms |
384 KB |
Output is correct |
17 |
Correct |
11 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
256 KB |
Output is correct |
19 |
Execution timed out |
1087 ms |
384 KB |
Time limit exceeded |
20 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
813 ms |
404 KB |
Output is correct |
2 |
Execution timed out |
1096 ms |
384 KB |
Time limit exceeded |
3 |
Execution timed out |
1093 ms |
384 KB |
Time limit exceeded |
4 |
Execution timed out |
1090 ms |
384 KB |
Time limit exceeded |
5 |
Correct |
278 ms |
384 KB |
Output is correct |
6 |
Execution timed out |
1020 ms |
504 KB |
Time limit exceeded |
7 |
Correct |
20 ms |
384 KB |
Output is correct |
8 |
Correct |
18 ms |
512 KB |
Output is correct |
9 |
Correct |
25 ms |
360 KB |
Output is correct |
10 |
Correct |
31 ms |
384 KB |
Output is correct |
11 |
Correct |
779 ms |
384 KB |
Output is correct |
12 |
Correct |
170 ms |
384 KB |
Output is correct |
13 |
Correct |
45 ms |
384 KB |
Output is correct |
14 |
Correct |
284 ms |
504 KB |
Output is correct |
15 |
Correct |
326 ms |
384 KB |
Output is correct |
16 |
Execution timed out |
1090 ms |
384 KB |
Time limit exceeded |
17 |
Execution timed out |
1085 ms |
384 KB |
Time limit exceeded |
18 |
Execution timed out |
1089 ms |
384 KB |
Time limit exceeded |
19 |
Execution timed out |
1095 ms |
384 KB |
Time limit exceeded |
20 |
Execution timed out |
1095 ms |
384 KB |
Time limit exceeded |
21 |
Execution timed out |
1092 ms |
384 KB |
Time limit exceeded |
22 |
Execution timed out |
1090 ms |
384 KB |
Time limit exceeded |
23 |
Execution timed out |
1089 ms |
384 KB |
Time limit exceeded |
24 |
Execution timed out |
1093 ms |
384 KB |
Time limit exceeded |
25 |
Execution timed out |
1096 ms |
384 KB |
Time limit exceeded |
26 |
Execution timed out |
1098 ms |
384 KB |
Time limit exceeded |
27 |
Execution timed out |
1092 ms |
384 KB |
Time limit exceeded |
28 |
Execution timed out |
1095 ms |
384 KB |
Time limit exceeded |
29 |
Execution timed out |
1097 ms |
372 KB |
Time limit exceeded |
30 |
Execution timed out |
1097 ms |
384 KB |
Time limit exceeded |
31 |
Execution timed out |
1099 ms |
384 KB |
Time limit exceeded |
32 |
Execution timed out |
1093 ms |
384 KB |
Time limit exceeded |
33 |
Execution timed out |
1083 ms |
384 KB |
Time limit exceeded |
34 |
Execution timed out |
1096 ms |
384 KB |
Time limit exceeded |
35 |
Execution timed out |
1078 ms |
384 KB |
Time limit exceeded |
36 |
Execution timed out |
1095 ms |
384 KB |
Time limit exceeded |
37 |
Execution timed out |
1094 ms |
384 KB |
Time limit exceeded |
38 |
Execution timed out |
1096 ms |
384 KB |
Time limit exceeded |
39 |
Execution timed out |
1091 ms |
384 KB |
Time limit exceeded |
40 |
Execution timed out |
1091 ms |
384 KB |
Time limit exceeded |
41 |
Execution timed out |
1087 ms |
384 KB |
Time limit exceeded |
42 |
Execution timed out |
1092 ms |
384 KB |
Time limit exceeded |
43 |
Execution timed out |
1086 ms |
384 KB |
Time limit exceeded |
44 |
Execution timed out |
1083 ms |
384 KB |
Time limit exceeded |
45 |
Execution timed out |
1096 ms |
384 KB |
Time limit exceeded |