Submission #1102879

# Submission time Handle Problem Language Result Execution time Memory
1102879 2024-10-19T06:48:34 Z haianhnguyen08102007 Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
1 ms 508 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
 
const int MAXN = 19;
int dp[MAXN][2][11][11];
 
string s;
 
int d(int i) {
    return (s[i] - '0');
}
 
int calc(int x) {
    if (x < 1) return x + 1;
    s = to_string(x);
    int tam = s.size();
    reverse(s.begin(), s.end());
    memset(dp, 0, sizeof dp);
    for (int i = 0; i <= 9; i++) dp[0][1][i][10] = 1;
    for (int i = 0; i <= d(0); i++) dp[0][0][i][10] = 1;
    for (int i = 1; i < tam; i++) {
        // calc 1
        for (int a = 0; a <= 9; a++) {
            for (int b = 0; b <= 9; b++) {
                for (int c = 0; c <= 10; c++) {
                    if ((a == b) || (a == c)) continue;
                    dp[i][1][a][b] += dp[i - 1][1][b][c];
                }
            }
        }
        // calc 0
        for (int a = 0; a < d(i); a++) {
            for (int b = 0; b <= 9; b++) {
                for (int c = 0; c <= 10; c++) {
                    if ((a == b) || (a == c)) continue;
                    dp[i][0][a][b] += dp[i - 1][1][b][c];
                }
            }
        }
        int a = d(i);
        for (int b = 0; b <= 9; b++) {
            for (int c = 0; c <= 10; c++) {
                if ((a == b) || (a == c)) continue;
                dp[i][0][a][b] += dp[i - 1][0][b][c];
            }
        }
    }
    int ans = 1;
    for (int i = 0; i < (tam - 1); i++) {
        for (int b = 1; b <= 10; b++) {
            for (int c = 0; c <= 10; c++) {
                ans += dp[i][1][b][c];
            }
        }
    }
    for (int b = 1; b <= 10; b++) {
        for (int c = 0; c <= 10; c++) {
            ans += dp[tam - 1][0][b][c];
            //cout << b << " " << c << " " << dp[tam - 1][0][b][c] << "\n";
        }
    }
    return ans;
}
 
int32_t main() {
    int a, b;
    cin >> a >> b;
    cout << calc(b) - calc(a - 1) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 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 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 444 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 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 508 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 508 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 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 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 508 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct