답안 #83249

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83249 2018-11-06T11:02:19 Z teomrn Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
3 ms 980 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long i64;

int cifre[20];
i64 dp[20][11][11][2];


i64 solve(i64 nr)
{
    if (nr == 0)
        return 1;
    if (nr < 0)
        return 0;

    int n = 0;
    while (nr) {
        cifre[++n] = nr % 10 + 1;
        nr /= 10;
    }
    reverse(cifre + 1, cifre + n + 1);
    memset(dp, 0, sizeof dp);

    dp[0][0][0][1] = 1;

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= 10; j++) {
            for (int k = 0; k <= 10; k++) {
                if ((k == 0 && j != 0) || (k != 0 && k == j) || (j == 0 && k == 1))
                    continue; /// pozitie ilegala
                for (int last = 0; last <= 10; last++) {
                    if (last == k && last != 0)
                        continue;
                    if (k == cifre[i])
                        dp[i][j][k][1] += dp[i - 1][last][j][1];
                    else if (k < cifre[i])
                        dp[i][j][k][0] += dp[i - 1][last][j][1];
                    dp[i][j][k][0] += dp[i - 1][last][j][0];
                }
            }
        }
    }

    i64 ans = 0;
    for (int j = 0; j <= 10; j++)
        for (int k = 0; k <= 10; k++)
            ans += dp[n][j][k][0] + dp[n][j][k][1];
    return ans;
}


int main()
{
    i64 a, b;
    cin >> a >> b;
    i64 ans = solve(b);
    ans -= solve(a - 1);

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 452 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 660 KB Output is correct
7 Correct 2 ms 660 KB Output is correct
8 Correct 2 ms 660 KB Output is correct
9 Correct 2 ms 660 KB Output is correct
10 Correct 2 ms 692 KB Output is correct
11 Correct 2 ms 692 KB Output is correct
12 Correct 2 ms 692 KB Output is correct
13 Correct 2 ms 692 KB Output is correct
14 Correct 2 ms 692 KB Output is correct
15 Correct 2 ms 692 KB Output is correct
16 Correct 2 ms 780 KB Output is correct
17 Correct 2 ms 780 KB Output is correct
18 Correct 2 ms 780 KB Output is correct
19 Correct 3 ms 780 KB Output is correct
20 Correct 2 ms 824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 824 KB Output is correct
2 Correct 2 ms 824 KB Output is correct
3 Correct 3 ms 824 KB Output is correct
4 Correct 3 ms 824 KB Output is correct
5 Correct 2 ms 824 KB Output is correct
6 Correct 2 ms 824 KB Output is correct
7 Correct 2 ms 824 KB Output is correct
8 Correct 2 ms 824 KB Output is correct
9 Correct 2 ms 824 KB Output is correct
10 Correct 2 ms 824 KB Output is correct
11 Correct 2 ms 884 KB Output is correct
12 Correct 2 ms 884 KB Output is correct
13 Correct 2 ms 884 KB Output is correct
14 Correct 2 ms 884 KB Output is correct
15 Correct 2 ms 884 KB Output is correct
16 Correct 2 ms 884 KB Output is correct
17 Correct 2 ms 884 KB Output is correct
18 Correct 2 ms 884 KB Output is correct
19 Correct 2 ms 884 KB Output is correct
20 Correct 2 ms 884 KB Output is correct
21 Correct 2 ms 884 KB Output is correct
22 Correct 2 ms 884 KB Output is correct
23 Correct 2 ms 884 KB Output is correct
24 Correct 2 ms 884 KB Output is correct
25 Correct 3 ms 884 KB Output is correct
26 Correct 2 ms 884 KB Output is correct
27 Correct 2 ms 884 KB Output is correct
28 Correct 2 ms 884 KB Output is correct
29 Correct 2 ms 884 KB Output is correct
30 Correct 2 ms 884 KB Output is correct
31 Correct 2 ms 968 KB Output is correct
32 Correct 2 ms 968 KB Output is correct
33 Correct 2 ms 968 KB Output is correct
34 Correct 2 ms 968 KB Output is correct
35 Correct 2 ms 968 KB Output is correct
36 Correct 2 ms 968 KB Output is correct
37 Correct 2 ms 968 KB Output is correct
38 Correct 2 ms 968 KB Output is correct
39 Correct 2 ms 968 KB Output is correct
40 Correct 2 ms 968 KB Output is correct
41 Correct 2 ms 968 KB Output is correct
42 Correct 3 ms 968 KB Output is correct
43 Correct 3 ms 976 KB Output is correct
44 Correct 2 ms 980 KB Output is correct
45 Correct 2 ms 980 KB Output is correct