#include<bits/stdc++.h>
using namespace std;
long long c,d,e,zx,xc,i,j,ii,jj,dp[22][12][12],p[22],pi,pas;
string a,b,aa,bb;
void rec(long long q, bool bo1, bool bo2){
//cout<<q<<" "<<bo1<<" "<<bo2<<endl;
if(q>=a.size()){
pas++;
return;
}
if(bo1==1&&bo2==1){
if(a.size()-q>=2){
for(i=0; i<=9; i++){
for(j=0; j<=9; j++){
if(i==j) continue;
if(p[pi]==i||p[pi]==j||p[pi-1]==i) continue;
pas+=dp[a.size()-q][i][j];
}
}
}else{
for(i=0; i<=9; i++){
if(i!=p[pi]&&i!=p[pi-1]) pas+=dp[1][i][0];
}
}
return;
}
for(long long h=0; h<=9; h++){
if(bo1==0&&h<a[q]-'0') continue;
if(bo2==0&&h>b[q]-'0') continue;
bool qw=bo1,we=bo2;
if(h>a[q]-'0') qw=1;
if(h<b[q]-'0') we=1;
pi++;p[pi]=h;
rec(q+1,qw,we);
pi--;
}
}
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>a>>b;
while(a.size()<b.size()) a.insert(0,"0");
dp[0][0][0]=1;
for(i=0; i<=9; i++) dp[1][i][0]=1;
for(i=2; i<=19; i++){
for(ii=0; ii<=9; ii++){
for(j=0; j<=9; j++){
if(ii==j) continue;
if(i==2){
dp[i][ii][j]+=dp[i-1][j][0];
continue;
}
for(jj=0; jj<=9; jj++){
if(ii==jj||j==jj) continue;
dp[i][ii][j]+=dp[i-1][j][jj];
}
}
}
}
p[0]=-1;
rec(0,0,0);
cout<<pas;
return 0;
}
Compilation message
numbers.cpp: In function 'void rec(long long int, bool, bool)':
numbers.cpp:7:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(q>=a.size()){
~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
8 |
Incorrect |
5 ms |
432 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
11 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
12 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
14 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
17 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
20 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
8 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
10 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
11 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
15 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
17 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
18 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
19 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
20 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
21 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
22 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
23 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
24 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
25 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
26 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
27 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
28 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
29 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
30 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
31 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
32 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
33 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
34 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
35 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
36 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
37 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
38 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
39 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
40 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
41 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
42 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
43 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
44 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
45 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |