답안 #490738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490738 2021-11-29T03:04:05 Z tht2005 Palindrome-Free Numbers (BOI13_numbers) C++14
96.25 / 100
1 ms 344 KB
#include <stdio.h>
#include <string.h>

#define LL  long long

int n;
char s[20];
LL dp[19][11][11][2][2];

LL calc(int i, int j, int k, int tight, int lz) {
    if(i == n) return 1;
    LL& res = dp[i][j][k][tight][lz];
    if(~res) return res;
    res = 0;
    if(tight) {
        if(lz) {
            res += calc(i + 1, 10, 10, 1, 1);
            for(int dig = 1; dig < 10; ++dig)
                res += calc(i + 1, 10, dig, 1, 0);
        }
        else {
            for(int dig = 0; dig < 10; ++dig) {
                if(dig != j && dig != k)
                    res += calc(i + 1, k, dig, 1, 0);
            }
        }
    }
    else {
        if(lz) {
            res += calc(i + 1, 10, 10, s[i] > '0', 1);
            for(int dig = 1; dig < s[i] - '0'; ++dig)
                res += calc(i + 1, k, dig, 1, 0);
            if(s[i] > '0' && s[i] != j + '0' && s[i] != k + '0')
                res += calc(i + 1, k, s[i] - '0', 0, 0);
        }
        else {
            for(int dig = 0; dig < s[i] - '0'; ++dig) {
                if(dig != j && dig != k) {
                    res += calc(i + 1, k, dig, 1, 0);
                }
            }
            if(s[i] != j + '0' && s[i] != k + '0')
                res += calc(i + 1, k, s[i] - '0', 0, 0);
        }
    }
    return res;
}

LL f(LL N) {
    sprintf(s, "%lld", N);
    n = strlen(s);
    memset(dp, -1, sizeof(dp));
    return calc(0, 10, 10, 0, 1);
}

int main() {
    LL L, R;
    scanf("%lld %lld", &L, &R);
    printf("%lld", f(R) - f(L - 1));
    return 0;
}

Compilation message

numbers.cpp: In function 'int main()':
numbers.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     scanf("%lld %lld", &L, &R);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Incorrect 0 ms 332 KB Output isn't correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Incorrect 1 ms 332 KB Output isn't correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 0 ms 336 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 0 ms 336 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 332 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 344 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 344 KB Output is correct