#include <iostream>
#include <cstdio>
#include <iomanip>
#include <chrono>
#include <sstream>
#include <cstring>
#define Kami
#define taskname "TEST"
using namespace std;
long long f[20][10][10][20][2];
string s;
inline long long Dp(const int &pos, const int &p1, const int &p2, const int &curLen, const bool &pref){
if(pos>=(int)s.size()) return 1;
long long &res=f[pos][p1][p2][curLen][pref];
if(res!=-1) return res;
res=0;
int lim=pref? s[pos]-'0' : 9;
for(int x=0;x<=lim;x++){
bool newPref=(pref && x==lim);
if(curLen==0){
if(x) res+=Dp(pos+1,0,x,curLen+1,newPref);
else res+=Dp(pos+1,0,x,curLen,newPref);
} else if(x!=p2 && ((curLen>1 && x!=p1) || curLen==1)){
res+=Dp(pos+1,p2,x,curLen+1,newPref);
}
}
return res;
}
inline long long Solve(const long long &x){
stringstream ss;
ss<<x; ss>>s;
memset(f,-1,sizeof(f));
return Dp(0,0,0,0,1);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL); if(fopen(taskname".INP","r"))
freopen(taskname".INP","r",stdin),
freopen(taskname".OUT","w",stdout);
#ifdef Kami
auto start=chrono::steady_clock::now();
#endif
long long a,b;
cin>>a>>b;
cout<<Solve(b)-Solve(a-1);
#ifdef Kami
auto end=chrono::steady_clock::now();
cerr<<"\nIn milliseconds : "
<<chrono::duration_cast<chrono::milliseconds>(end-start).count();
cerr<<'\n'<<"In seconds : "<<fixed<<setprecision(3)
<<(double)chrono::duration_cast<chrono::milliseconds>(end-start).count()/1000<<'\n';
#endif
return 0;
}
Compilation message
numbers.cpp: In function 'int main()':
numbers.cpp:42:38: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(taskname".INP","r",stdin),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
freopen(taskname".OUT","w",stdout);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
numbers.cpp:42:38: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
3 |
Incorrect |
6 ms |
1016 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
15 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
16 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
17 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
18 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
19 |
Incorrect |
6 ms |
1016 KB |
Output isn't correct |
20 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
1016 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
1016 KB |
Output isn't correct |
3 |
Incorrect |
6 ms |
1020 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
988 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
892 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
9 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
1016 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
1016 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
888 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
15 |
Incorrect |
4 ms |
1016 KB |
Output isn't correct |
16 |
Incorrect |
7 ms |
1144 KB |
Output isn't correct |
17 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
18 |
Incorrect |
6 ms |
1016 KB |
Output isn't correct |
19 |
Incorrect |
7 ms |
888 KB |
Output isn't correct |
20 |
Incorrect |
6 ms |
1016 KB |
Output isn't correct |
21 |
Incorrect |
6 ms |
1016 KB |
Output isn't correct |
22 |
Incorrect |
6 ms |
1004 KB |
Output isn't correct |
23 |
Incorrect |
3 ms |
1016 KB |
Output isn't correct |
24 |
Incorrect |
6 ms |
1016 KB |
Output isn't correct |
25 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
26 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
27 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
28 |
Incorrect |
6 ms |
1192 KB |
Output isn't correct |
29 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
30 |
Incorrect |
6 ms |
1016 KB |
Output isn't correct |
31 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
32 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
33 |
Incorrect |
5 ms |
888 KB |
Output isn't correct |
34 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
35 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
36 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
37 |
Incorrect |
6 ms |
1016 KB |
Output isn't correct |
38 |
Incorrect |
6 ms |
1016 KB |
Output isn't correct |
39 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
40 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
41 |
Incorrect |
6 ms |
892 KB |
Output isn't correct |
42 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
43 |
Incorrect |
6 ms |
892 KB |
Output isn't correct |
44 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |
45 |
Incorrect |
6 ms |
888 KB |
Output isn't correct |