답안 #490737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490737 2021-11-29T03:00:35 Z tht2005 Palindrome-Free Numbers (BOI13_numbers) C++14
38.75 / 100
1 ms 340 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, "%d", 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 'long long int f(long long int)':
numbers.cpp:50:18: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long long int' [-Wformat=]
   50 |     sprintf(s, "%d", N);
      |                 ~^   ~
      |                  |   |
      |                  int long long int
      |                 %lld
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 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Incorrect 0 ms 332 KB Output isn't correct
5 Correct 1 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 1 ms 332 KB Output is correct
12 Correct 0 ms 276 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 1 ms 332 KB Output is correct
18 Incorrect 0 ms 332 KB Output isn't correct
19 Incorrect 1 ms 332 KB Output isn't correct
20 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't 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 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 1 ms 332 KB Output is correct
13 Correct 1 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 Incorrect 0 ms 332 KB Output isn't correct
17 Incorrect 0 ms 332 KB Output isn't correct
18 Incorrect 0 ms 332 KB Output isn't correct
19 Incorrect 0 ms 332 KB Output isn't correct
20 Incorrect 0 ms 332 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 0 ms 332 KB Output isn't correct
26 Incorrect 0 ms 332 KB Output isn't correct
27 Incorrect 0 ms 332 KB Output isn't correct
28 Incorrect 1 ms 332 KB Output isn't correct
29 Incorrect 0 ms 340 KB Output isn't correct
30 Incorrect 0 ms 336 KB Output isn't correct
31 Incorrect 0 ms 336 KB Output isn't correct
32 Incorrect 0 ms 340 KB Output isn't correct
33 Incorrect 1 ms 336 KB Output isn't correct
34 Incorrect 0 ms 336 KB Output isn't correct
35 Incorrect 0 ms 340 KB Output isn't correct
36 Incorrect 0 ms 336 KB Output isn't correct
37 Incorrect 0 ms 336 KB Output isn't correct
38 Incorrect 0 ms 340 KB Output isn't correct
39 Incorrect 0 ms 332 KB Output isn't correct
40 Incorrect 1 ms 340 KB Output isn't correct
41 Incorrect 0 ms 340 KB Output isn't correct
42 Incorrect 0 ms 336 KB Output isn't correct
43 Incorrect 0 ms 332 KB Output isn't correct
44 Incorrect 1 ms 260 KB Output isn't correct
45 Incorrect 0 ms 336 KB Output isn't correct