#include <bits/stdc++.h>
using namespace std;
long long int N,M,dp[10][10][100][10];
vector <long long int> s;
long long int cnt(long long int p1,long long int p2,long long int pos,long long int ma)
{
long long int sum=0,i;
if(pos>=s.size()) return 1;
if(dp[p1][p2][pos][ma]!=-1) return dp[p1][p2][pos][ma];
if(ma==0)
{
for(i=0;i<=9;i++)
{
if(i==p1||i==p2) continue;
sum+=cnt(i,p1,pos+1,0);
}
}
else
{
for(i=0;i<s[pos];i++)
{
if(i==p1||i==p2) continue;
sum+=cnt(i,p1,pos+1,0);
}
if(s[pos]==p1||s[pos]==p2){}
else sum+=cnt(s[pos],p1,pos+1,1);
}
dp[p1][p2][pos][ma]=sum;
return sum;
}
long long int cp(long long int n)
{
if(n<0) return 0;
if(n==0) return 1;
s.clear();
memset(dp,-1,sizeof(dp));
long long int i,j,x,sum=1;
x=n;
while(x!=0)
{
s.push_back(x%10);
x/=10;
}
reverse(s.begin(),s.end());
for(i=1;i<s[0];i++)
{
sum+=cnt(i,i,1,0);
}
sum+=cnt(s[0],s[0],1,1);
for(j=2;i<=s.size();j++)
{
for(i=1;i<=9;i++)
{
sum+=cnt(i,i,j,0);
}
}
return sum;
}
int main()
{
scanf("%lld %lld",&N,&M);
printf("%lld",cp(M)-cp(N-1));
return 0;
}
Compilation message
numbers.cpp: In function 'long long int cnt(long long int, long long int, long long int, long long int)':
numbers.cpp:10:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | if(pos>=s.size()) return 1;
| ~~~^~~~~~~~~~
numbers.cpp: In function 'long long int cp(long long int)':
numbers.cpp:53:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(j=2;i<=s.size();j++)
| ~^~~~~~~~~~
numbers.cpp: In function 'int main()':
numbers.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%lld %lld",&N,&M);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
1068 KB |
Output isn't correct |
3 |
Execution timed out |
1077 ms |
972 KB |
Time limit exceeded |
4 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
1072 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
9 |
Correct |
1 ms |
972 KB |
Output is correct |
10 |
Correct |
1 ms |
972 KB |
Output is correct |
11 |
Correct |
1 ms |
972 KB |
Output is correct |
12 |
Correct |
1 ms |
1068 KB |
Output is correct |
13 |
Correct |
1 ms |
972 KB |
Output is correct |
14 |
Incorrect |
1 ms |
1072 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
16 |
Correct |
1 ms |
1068 KB |
Output is correct |
17 |
Correct |
1 ms |
972 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Execution timed out |
1069 ms |
1068 KB |
Time limit exceeded |
20 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Execution timed out |
1087 ms |
972 KB |
Time limit exceeded |
3 |
Execution timed out |
1063 ms |
972 KB |
Time limit exceeded |
4 |
Execution timed out |
1063 ms |
1060 KB |
Time limit exceeded |
5 |
Incorrect |
1 ms |
964 KB |
Output isn't correct |
6 |
Correct |
1 ms |
1048 KB |
Output is correct |
7 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
1080 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
1072 KB |
Output isn't correct |
11 |
Correct |
1 ms |
972 KB |
Output is correct |
12 |
Incorrect |
1 ms |
1052 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
1068 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
1072 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
16 |
Execution timed out |
1086 ms |
972 KB |
Time limit exceeded |
17 |
Execution timed out |
1044 ms |
940 KB |
Time limit exceeded |
18 |
Execution timed out |
1060 ms |
932 KB |
Time limit exceeded |
19 |
Execution timed out |
1077 ms |
1100 KB |
Time limit exceeded |
20 |
Execution timed out |
1044 ms |
940 KB |
Time limit exceeded |
21 |
Execution timed out |
1034 ms |
972 KB |
Time limit exceeded |
22 |
Execution timed out |
1070 ms |
1068 KB |
Time limit exceeded |
23 |
Execution timed out |
1006 ms |
940 KB |
Time limit exceeded |
24 |
Execution timed out |
1037 ms |
936 KB |
Time limit exceeded |
25 |
Execution timed out |
1065 ms |
964 KB |
Time limit exceeded |
26 |
Execution timed out |
1014 ms |
1052 KB |
Time limit exceeded |
27 |
Execution timed out |
1041 ms |
964 KB |
Time limit exceeded |
28 |
Execution timed out |
1056 ms |
932 KB |
Time limit exceeded |
29 |
Execution timed out |
1084 ms |
972 KB |
Time limit exceeded |
30 |
Execution timed out |
1059 ms |
972 KB |
Time limit exceeded |
31 |
Execution timed out |
1048 ms |
1112 KB |
Time limit exceeded |
32 |
Execution timed out |
1043 ms |
972 KB |
Time limit exceeded |
33 |
Execution timed out |
1022 ms |
1048 KB |
Time limit exceeded |
34 |
Execution timed out |
1044 ms |
1076 KB |
Time limit exceeded |
35 |
Execution timed out |
1049 ms |
1048 KB |
Time limit exceeded |
36 |
Execution timed out |
1034 ms |
1052 KB |
Time limit exceeded |
37 |
Execution timed out |
1008 ms |
936 KB |
Time limit exceeded |
38 |
Execution timed out |
1008 ms |
1052 KB |
Time limit exceeded |
39 |
Execution timed out |
1076 ms |
1068 KB |
Time limit exceeded |
40 |
Execution timed out |
1052 ms |
1068 KB |
Time limit exceeded |
41 |
Execution timed out |
1042 ms |
972 KB |
Time limit exceeded |
42 |
Execution timed out |
1054 ms |
1052 KB |
Time limit exceeded |
43 |
Execution timed out |
1069 ms |
972 KB |
Time limit exceeded |
44 |
Execution timed out |
1051 ms |
1072 KB |
Time limit exceeded |
45 |
Execution timed out |
1069 ms |
1080 KB |
Time limit exceeded |