Submission #462607

# Submission time Handle Problem Language Result Execution time Memory
462607 2021-08-11T00:05:59 Z JovanB Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
4 ms 436 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
ll dp[3][25][15][15];

string tostr(ll n){
    string s = "";
    while(n){
        s += '0' + (n%10);
        n /= 10;
    }
    reverse(s.begin(), s.end());
    return s;
}
 
ll solve(ll n){
    for(int i=0; i<=20; i++){
        for(int j=0; j<=10; j++){
            for(int k=0; k<=10; k++){
                for(int l=0; l<=10; l++){
                    dp[0][i][j][k] = dp[1][i][j][k] = dp[2][i][j][k] = 0;
                }
            }
        }
    }
    dp[0][0][0][0] = 1;
    string s = tostr(n);
    int len = s.size();
    for(int i=0; i<len; i++){
        for(int j=0; j<=10; j++){
            for(int k=0; k<=10; k++){
                for(int l=1; l<=10; l++){
                    if(l == j || l == k) continue;
                    if(!i && l == 1) continue;
                    dp[1][i+1][k][l] += dp[1][i][j][k];
                    if(l-1 < s[i]-'0'){
                        dp[1][i+1][k][l] += dp[0][i][j][k];
                    }
                    if(l-1 == s[i]-'0'){
                        dp[0][i+1][k][l] += dp[0][i][j][k];
                    }
                }
            }
        }
    }
    ll res = 0;
    for(int i=0; i<=10; i++){
        for(int j=0; j<=10; j++){
            res += dp[0][len][i][j] + dp[1][len][i][j];
        }
    }
    return res;
}
 
ll resi(ll n){
    ll k = 0;
    ll res = 0;
    while(k < n){
        res += solve(k);
        k = 10*k+9;
    }
    res += solve(n);
    return res;
}
 
int main(){
    ios_base::sync_with_stdio(false);
 
    ll a, b;
    cin >> a >> b;
    cout << resi(b) - resi(a-1);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 352 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 432 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 3 ms 436 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 2 ms 316 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 3 ms 332 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 3 ms 332 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 2 ms 332 KB Output is correct
35 Correct 3 ms 332 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 2 ms 332 KB Output is correct
38 Correct 3 ms 332 KB Output is correct
39 Correct 3 ms 332 KB Output is correct
40 Correct 3 ms 332 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 2 ms 312 KB Output is correct
43 Correct 4 ms 332 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 4 ms 332 KB Output is correct