답안 #77206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77206 2018-09-24T01:36:20 Z EntityIT Palindrome-Free Numbers (BOI13_numbers) C++14
100 / 100
3 ms 700 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long

int a, b, arr[19], dp[19][10][10][2][2];

int calc (int pos, int las1, int las2, bool smaller, bool nonZero) {
    if ( (nonZero || las1) && las1 == las2) return 0;
    if (pos == 1) {
        if (smaller || las1 < arr[pos] || (las1 == arr[pos] && las2 <= arr[pos - 1]) ) return 1;
    }
    int &ret = dp[pos][las1][las2][smaller][nonZero];
    if (ret != -1) return ret;
    ret = 0;
    if (smaller || las1 < arr[pos] || (las1 == arr[pos] && las2 <= arr[pos - 1]) ) {
        for (int las3 = 0; las3 < 10; ++las3) {
            if ( (nonZero || las1) && las1 == las3) continue ;
            ret += calc(pos - 1, las2, las3, max(smaller, (las1 < arr[pos]) ), max(nonZero, (las1 > 0) ) );
        }
    }
    return ret;
}

int solve (int lim) {
    memset(dp, -1, sizeof dp);
    if (lim < 0) return 0;
    int cur = 0;
    memset(arr, 0, sizeof arr);
    while (lim) {
        arr[cur++] = lim % 10; lim /= 10;
    }
    int ret = 0;
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            ret += calc(18, i, j, 0, 0);
        }
    }
    return ret;
}

signed main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> b;
    cout << solve(b) - solve(a - 1);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 2 ms 680 KB Output is correct
11 Correct 2 ms 680 KB Output is correct
12 Correct 2 ms 680 KB Output is correct
13 Correct 2 ms 680 KB Output is correct
14 Correct 2 ms 680 KB Output is correct
15 Correct 2 ms 680 KB Output is correct
16 Correct 3 ms 680 KB Output is correct
17 Correct 2 ms 680 KB Output is correct
18 Correct 2 ms 680 KB Output is correct
19 Correct 2 ms 680 KB Output is correct
20 Correct 2 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 680 KB Output is correct
2 Correct 3 ms 680 KB Output is correct
3 Correct 3 ms 680 KB Output is correct
4 Correct 2 ms 680 KB Output is correct
5 Correct 3 ms 680 KB Output is correct
6 Correct 2 ms 680 KB Output is correct
7 Correct 2 ms 680 KB Output is correct
8 Correct 3 ms 680 KB Output is correct
9 Correct 2 ms 680 KB Output is correct
10 Correct 3 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 3 ms 692 KB Output is correct
14 Correct 3 ms 692 KB Output is correct
15 Correct 2 ms 692 KB Output is correct
16 Correct 2 ms 692 KB Output is correct
17 Correct 2 ms 692 KB Output is correct
18 Correct 3 ms 692 KB Output is correct
19 Correct 2 ms 692 KB Output is correct
20 Correct 2 ms 692 KB Output is correct
21 Correct 2 ms 692 KB Output is correct
22 Correct 2 ms 692 KB Output is correct
23 Correct 2 ms 692 KB Output is correct
24 Correct 2 ms 692 KB Output is correct
25 Correct 2 ms 692 KB Output is correct
26 Correct 2 ms 692 KB Output is correct
27 Correct 2 ms 692 KB Output is correct
28 Correct 2 ms 692 KB Output is correct
29 Correct 2 ms 692 KB Output is correct
30 Correct 2 ms 692 KB Output is correct
31 Correct 2 ms 692 KB Output is correct
32 Correct 2 ms 700 KB Output is correct
33 Correct 2 ms 700 KB Output is correct
34 Correct 2 ms 700 KB Output is correct
35 Correct 2 ms 700 KB Output is correct
36 Correct 2 ms 700 KB Output is correct
37 Correct 3 ms 700 KB Output is correct
38 Correct 3 ms 700 KB Output is correct
39 Correct 2 ms 700 KB Output is correct
40 Correct 2 ms 700 KB Output is correct
41 Correct 2 ms 700 KB Output is correct
42 Correct 2 ms 700 KB Output is correct
43 Correct 3 ms 700 KB Output is correct
44 Correct 2 ms 700 KB Output is correct
45 Correct 2 ms 700 KB Output is correct