Submission #547250

# Submission time Handle Problem Language Result Execution time Memory
547250 2022-04-10T05:01:22 Z Jomnoi Palindrome-Free Numbers (BOI13_numbers) C++17
72.5 / 100
2 ms 360 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

long long dp[20][2][11][11];

long long solve2(string s, int idx = 0, bool f = false, int p1 = 10, int p2 = 10) {
    if(dp[idx][f][p1][p2] != -1) {
        return dp[idx][f][p1][p2];
    }
    if(idx == s.size()) {
        return 1;
    }

    int len = 9;
    if(f == false) {
        len = s[idx] - '0';
    }

    long long res = 0;
    for(int i = 0; i <= len; i++) {
        bool nf = f;
        if(i < len) {
            nf = true;
        }

        if(i == p1 or i == p2) {
            continue;
        }
        res += solve2(s, idx + 1, nf, i, p1);
    }
    return dp[idx][f][p1][p2] = res;
}

long long solve(long long a) {
    for(int i = 0; i < 20; i++) {
        for(int j = 0; j <= 10; j++) {
            for(int k = 0; k <= 10; k++) {
                dp[i][0][j][k] = dp[i][1][j][k] = -1;
            }
        }
    }

    string t;
    while(a > 0) {
        t.push_back(a % 10 + '0');
        a /= 10;
    }
    reverse(t.begin(), t.end());

    return solve2(t);
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    long long a, b, ans;
    cin >> a >> b;
    ans = solve(b);
    if(a > 0) {
        ans -= solve(a - 1);
    }
    cout << ans;
    return 0;
}

Compilation message

numbers.cpp: In function 'long long int solve2(std::string, int, bool, int, int)':
numbers.cpp:11:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     if(idx == s.size()) {
      |        ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 328 KB Output isn't correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 0 ms 340 KB Output isn't 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 340 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 328 KB Output isn't correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Incorrect 0 ms 340 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Correct 1 ms 340 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Incorrect 1 ms 324 KB Output isn't correct
11 Correct 1 ms 340 KB Output is correct
12 Incorrect 1 ms 340 KB Output isn't correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 2 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 328 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 332 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 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 360 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 328 KB Output is correct
42 Correct 1 ms 328 KB Output is correct
43 Correct 1 ms 324 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct