Submission #711947

# Submission time Handle Problem Language Result Execution time Memory
711947 2023-03-17T18:11:25 Z lukameladze Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
2 ms 480 KB
# include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
#define pii pair <int, int>
#define pb push_back
const int N = 3e5 + 5;
int t,n,a[N];
int dp[21][11][11][2][2][2];
int get(int x) {
    if (x < 0) return 0;
    if (x == 0) return 1;
    string s = to_string(x);
    memset(dp, 0, sizeof(dp));
    dp[0][10][10][0][0][0] = 1;
    s = "@" + s;
    for (int i = 1; i < (int)s.size(); i++) {
        for (int cur = 0; cur <= 9; cur++) {
            for (int pr_lst = 0; pr_lst <= 10; pr_lst++) {
                for (int lst = 0; lst <= 10; lst++) {
                    for (int less = 0; less <= 1; less++) {
                        for (int started = 0; started <= 1; started++) {
                            int new_less = 0;
                            
                            if (!less && cur > (int)(s[i] - '0')) continue;
                            if (less || cur < (int)(s[i] - '0')) {
                                new_less = 1;
                            } else new_less = 0;
                            int st = (started || (cur > 0));
                            if ((cur != pr_lst && cur != lst) || (!started))
                            dp[i][(started ? lst : 10)][cur][0][new_less][st] += dp[i - 1][pr_lst][lst][0][less][started], dp[i][(started ? lst : 10)][cur][1][new_less][st] += dp[i - 1][pr_lst][lst][1][less][started];
                            else
                            dp[i][(started ? lst : 10)][cur][1][new_less][st] += (dp[i - 1][pr_lst][lst][0][less][started] + dp[i - 1][pr_lst][lst][1][less][started]);
                        }
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = (int)s.size() - 1; i < (int)s.size(); i++) {
        for (int pr_lst = 0; pr_lst <= 10; pr_lst++) {
            for (int lst = 0; lst <= 10; lst++) {
                for (int st = 0; st <= 1; st++) {
                    ans += dp[i][pr_lst][lst][0][0][st];
                    ans += dp[i][pr_lst][lst][0][1][st];
                }
            }
        }
    }
    return ans;
}
main() {
    std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int a, b;
    cin>>a>>b;
    cout<<get(b) - get(a - 1)<<"\n";
}

Compilation message

numbers.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 480 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 368 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 1 ms 468 KB Output is correct
35 Correct 1 ms 468 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct