Submission #563433

#TimeUsernameProblemLanguageResultExecution timeMemory
563433tht2005Palindrome-Free Numbers (BOI13_numbers)C++17
72.50 / 100
1 ms340 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

char a[20];
LL f[20][10][10][2];

LL calc(LL x) {
    sprintf(a, "%lld", x);
    int n = strlen(a);
    for(int i = 0; i <= n; ++i) {
        memset(f[i], 0, sizeof(f[i]));
    }
    f[0][0][0][0] = 1;
    for(int i = 1; i < n; ++i) {
        f[i][0][0][1] = 1;
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < 10; ++j) {
            for(int k = 0; k < 10; ++k) {
                for(int t = 0; t < 2; ++t) {
                    LL ft = f[i][j][k][t];
                    if(ft == 0) continue;
                    for(int c = (i == 0); (t ? (c < 10) : (c <= a[i] - '0')); ++c) {
                        if(i && c == k) continue;
                        if(i > 1 && c == j) continue;
                        f[i + 1][k][c][t || (c < a[i] - '0')] += ft;
                    }
                }
            }
        }
    }
    LL res = 0;
    for(int i = 0; i < 10; ++i) {
        for(int j = 0; j < 10; ++j) {
            res += f[n][i][j][1];
        }
    }
    return res;
}

int main() {
    LL l, r;
    scanf("%lld %lld", &l, &r);
    printf("%lld", calc(r + 1) - calc(l));
    return 0;
}

Compilation message (stderr)

numbers.cpp: In function 'int main()':
numbers.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |     scanf("%lld %lld", &l, &r);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...