답안 #792261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792261 2023-07-24T22:50:04 Z PanosPask Palindrome-Free Numbers (BOI13_numbers) C++14
96.25 / 100
1 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXD = 18;
const int DIGCNT = 10;

ll A, B;
ll dp[MAXD + 1][DIGCNT + 1][DIGCNT + 1][2][2];
vector<int> number;

ll calc_dp(int pos = MAXD, int p1 = DIGCNT, int p2 = DIGCNT, bool smaller = false, bool leadz = true)
{
    if (pos == -1)
        return 1;

    if (dp[pos][p1][p2][smaller][leadz] != -1)
        return dp[pos][p1][p2][smaller][leadz];

    int v = number[pos];
    dp[pos][p1][p2][smaller][leadz] = 0;
    for (int l = 0; l < DIGCNT; l++) {
        if (l == 0 && leadz) {
            dp[pos][p1][p2][smaller][leadz] += calc_dp(pos - 1, p2, DIGCNT, smaller || v, true);
        }
        else {
            if (l == p1 || l == p2)
                continue;

            if (l < v) {
                dp[pos][p1][p2][smaller][leadz] += calc_dp(pos - 1, p2, l, true, false);
            }
            else if (l == v) {
                dp[pos][p1][p2][smaller][leadz] += calc_dp(pos - 1, p2, l, smaller, false);
            }
            else {
                if (smaller)
                    dp[pos][p1][p2][smaller][leadz] += calc_dp(pos - 1, p2, l, smaller, false);
            }
        }
    }

    return dp[pos][p1][p2][smaller][leadz];
}

void setnum(ll A)
{
    memset(dp, -1, sizeof(dp));
    number.clear();

    for (int i = 0; i < MAXD + 1; i++) {
        number.push_back(A % 10);
        A /= 10;
    }
}

int main(void)
{
    scanf("%lld %lld", &A, &B);

    ll ans = 0;
    setnum(A - 1);
    ans -= calc_dp();
    setnum(B);
    ans += calc_dp();

    printf("%lld\n", ans);
}

Compilation message

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