답안 #77194

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

using namespace std;

long long dp[20][2][2][11][11];
string a, b;

long long solve (int pos, bool low, bool high, int last, int prevlast, bool nonzero) {
    if (pos == a.length()) return 1;
    long long &ans = dp[pos][low][high][last][prevlast];
    if (ans != -1) return ans;

    ans = 0;
    int l = 0, r = 9;
    if (low) l = a[pos] - '0';
    if (high) r = b[pos] - '0';

    for (int i = l; i <= r; i++) {
        bool newlow = 0;
        bool newhigh = 0;
        if (low && i == l) newlow = 1;
        if (high && i == r) newhigh = 1;

        if (!nonzero) {
            if (i == 0) ans += solve(pos + 1, newlow, newhigh, last, prevlast, nonzero);
            else if (i != last && i != prevlast) ans += solve(pos + 1, newlow, newhigh, i, last, true);
        }
        else if (i != last && i != prevlast) ans += solve(pos + 1, newlow, newhigh, i, last, true);
    }

    return ans;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b;
    while (a.length() < b.length()) a = "0" + a;
    while (b.length() < a.length()) b = "0" + b;
    memset(dp, -1, sizeof(dp));
    cout << solve(0, 1, 1, 10, 10, 0);
    return 0;
}

Compilation message

numbers.cpp: In function 'long long int solve(int, bool, bool, int, int, bool)':
numbers.cpp:9:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (pos == a.length()) return 1;
         ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 580 KB Output is correct
4 Correct 2 ms 580 KB Output is correct
5 Correct 2 ms 580 KB Output is correct
6 Correct 2 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 2 ms 688 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 3 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 796 KB Output is correct
6 Correct 2 ms 796 KB Output is correct
7 Correct 2 ms 796 KB Output is correct
8 Correct 2 ms 796 KB Output is correct
9 Correct 2 ms 796 KB Output is correct
10 Correct 2 ms 796 KB Output is correct
11 Correct 2 ms 796 KB Output is correct
12 Correct 2 ms 796 KB Output is correct
13 Correct 2 ms 796 KB Output is correct
14 Correct 2 ms 796 KB Output is correct
15 Correct 2 ms 796 KB Output is correct
16 Correct 2 ms 796 KB Output is correct
17 Correct 2 ms 796 KB Output is correct
18 Correct 2 ms 796 KB Output is correct
19 Correct 2 ms 796 KB Output is correct
20 Correct 2 ms 796 KB Output is correct
21 Correct 2 ms 796 KB Output is correct
22 Correct 2 ms 796 KB Output is correct
23 Correct 2 ms 796 KB Output is correct
24 Correct 2 ms 796 KB Output is correct
25 Correct 2 ms 796 KB Output is correct
26 Correct 2 ms 796 KB Output is correct
27 Correct 2 ms 796 KB Output is correct
28 Correct 2 ms 796 KB Output is correct
29 Correct 2 ms 796 KB Output is correct
30 Correct 2 ms 796 KB Output is correct
31 Correct 2 ms 796 KB Output is correct
32 Correct 2 ms 796 KB Output is correct
33 Correct 2 ms 796 KB Output is correct
34 Correct 2 ms 796 KB Output is correct
35 Correct 2 ms 796 KB Output is correct
36 Correct 2 ms 796 KB Output is correct
37 Correct 3 ms 796 KB Output is correct
38 Correct 2 ms 796 KB Output is correct
39 Correct 2 ms 796 KB Output is correct
40 Correct 2 ms 796 KB Output is correct
41 Correct 2 ms 796 KB Output is correct
42 Correct 2 ms 796 KB Output is correct
43 Correct 2 ms 796 KB Output is correct
44 Correct 2 ms 796 KB Output is correct
45 Correct 2 ms 796 KB Output is correct