Submission #535260

# Submission time Handle Problem Language Result Execution time Memory
535260 2022-03-09T20:34:50 Z __Variatto Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
ll dp[20][2][10][10];
ll policz(ll x){
    for(int i=1; i<=19; i++)
        for(int a=0; a<=9; a++)
            for(int b=0; b<=9; b++)
                dp[i][0][a][b]=dp[i][1][a][b]=0;
    ll x1=x, i=1, a1=-1, a2=-1;
    while(x1){
        int curr=x1%10;
        if(a1!=-1&&a2==-1) a2=curr;
        if(a1==-1) a1=curr;
        x1/=10, i++;
        if(a1!=-1&&a2!=-1) break;
    }
    for(int a=0; a<=9; a++){
        for(int b=0; b<=9; b++){
            if(a==b)
                continue;
            if((a<a2)||(a==a2 && b<=a1))
                dp[2][0][a][b]=1;
            dp[2][1][a][b]=1;
        }
    }
    while(x1){
        int curr=x1%10;
        for(int a=0; a<=9; a++){
            for(int b=0; b<=9; b++){
                for(int c=0; c<=9; c++){
                    if(a==b||b==c||a==c)
                        continue;
                    dp[i][1][a][b]+=dp[i-1][1][b][c];
                    if(a==curr)
                        dp[i][0][a][b]+=dp[i-1][0][b][c];
                    if(a<curr)
                        dp[i][0][a][b]+=dp[i-1][1][b][c];
                }
            }
        }
        x1/=10, i++;
    }
    if(x<10)
        return x+1;
    ll wyn=0;
    //cout<<dp[3][0][0][1]<<"\n";
    for(int j=2; j<i-1; j++){
        for(int a=1; a<=9; a++)
            for(int b=0; b<=9; b++)
                wyn+=dp[j][1][a][b];
    }
    for(int a=1; a<=9; a++)
        for(int b=0; b<=9; b++)
            wyn+=dp[i-1][0][a][b];

    return wyn+10;
}
ll x, y;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>x>>y;
    cout<<policz(y)-policz(x-1)<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 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 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 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 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 0 ms 340 KB Output is correct