Submission #518262

# Submission time Handle Problem Language Result Execution time Memory
518262 2022-01-23T09:22:17 Z Ai7081 Palindrome-Free Numbers (BOI13_numbers) C++17
20 / 100
1 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define long long long
const bool debug = 0;

long a, b, pow8[20], dp[20][15][15], d[20][15], sum[20][15];

long round(long x, long k) {
    x /= pow(10, k);
    return x * pow(10, k);
}

long until(long x) {
    if (x < 10) return x+1;
    vector<long> unit;
    while (x > 0) unit.push_back(x%10), x/=10;
    long ret = 0;
    ret += sum[unit.size()][unit[unit.size()-1] - 1];
    for (int j=0; j<unit[unit.size()-2]; j++) ret += dp[unit.size()][unit[unit.size()-1]][j];
    for (int i=unit.size()-2; i>=1; i--) {
        for (int j=0; j<unit[i-1]; j++) {
            if (j != unit[i+1]) ret += dp[i+1][unit[i]][j];
        }
    }
    return ret;
}

long sol(long x, long y) {
    if (!x) return until(y);
    return until(y) - until(x-1);
}

int main() {
    pow8[0] = 1;
    for (int i=1; i<=18; i++) pow8[i] = pow8[i-1] * 8;
    for (int i=0; i<=9; i++) for (int j=0; j<=9; j++) if (i!=j) dp[2][i][j] = 1;
    for (int u=3; u<=18; u++) {
        for (int i=0; i<=9; i++) {
            for (int j=0; j<=9; j++) {
                if (i!=j) {
                    for (int k=0; k<=9; k++) {
                        if (i!=k && j!=k) dp[u][i][j] += dp[u-1][j][k];
                    }
                }
            }
        }
    }
    for (int i=0; i<=9; i++) d[1][i] = 1;
    for (int u=2; u<=18; u++) {
        for (int i=0; i<=9; i++) {
            for (int j=0; j<=9; j++) {
                d[u][i] += dp[u][i][j];
            }
        }
    }
    sum[1][0] = 1;
    for (int u=1; u<=18; u++) {
        for (int i=0; i<=9; i++) {
            if (!i && u!=1) sum[u][i] = sum[u-1][9];
            else sum[u][i] = sum[u][i-1] + d[u][i];
        }
    }

    scanf(" %lld %lld", &a, &b);
    printf("%lld", sol(a, b));
}

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf(" %lld %lld", &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Correct 0 ms 332 KB Output is correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Incorrect 1 ms 332 KB Output isn't correct
18 Correct 1 ms 332 KB Output is correct
19 Incorrect 1 ms 308 KB Output isn't correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 1 ms 312 KB Output isn't correct
5 Correct 1 ms 332 KB Output is correct
6 Incorrect 1 ms 332 KB Output isn't correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Incorrect 1 ms 384 KB Output isn't correct
10 Correct 0 ms 332 KB Output is correct
11 Incorrect 1 ms 328 KB Output isn't correct
12 Incorrect 1 ms 328 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Correct 1 ms 328 KB Output is correct
15 Incorrect 0 ms 332 KB Output isn't correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Incorrect 1 ms 332 KB Output isn't correct
18 Incorrect 1 ms 332 KB Output isn't correct
19 Incorrect 1 ms 332 KB Output isn't correct
20 Incorrect 1 ms 312 KB Output isn't correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Incorrect 1 ms 332 KB Output isn't correct
23 Incorrect 0 ms 332 KB Output isn't correct
24 Incorrect 1 ms 332 KB Output isn't correct
25 Incorrect 1 ms 332 KB Output isn't correct
26 Incorrect 1 ms 332 KB Output isn't correct
27 Incorrect 1 ms 328 KB Output isn't correct
28 Incorrect 1 ms 332 KB Output isn't correct
29 Incorrect 1 ms 332 KB Output isn't correct
30 Incorrect 0 ms 332 KB Output isn't correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Incorrect 0 ms 332 KB Output isn't correct
33 Incorrect 1 ms 332 KB Output isn't correct
34 Incorrect 1 ms 332 KB Output isn't correct
35 Incorrect 1 ms 332 KB Output isn't correct
36 Incorrect 1 ms 332 KB Output isn't correct
37 Incorrect 1 ms 332 KB Output isn't correct
38 Incorrect 1 ms 336 KB Output isn't correct
39 Incorrect 1 ms 212 KB Output isn't correct
40 Incorrect 0 ms 332 KB Output isn't correct
41 Incorrect 1 ms 340 KB Output isn't correct
42 Incorrect 0 ms 320 KB Output isn't correct
43 Incorrect 1 ms 332 KB Output isn't correct
44 Incorrect 1 ms 332 KB Output isn't correct
45 Incorrect 1 ms 332 KB Output isn't correct