Submission #95267

# Submission time Handle Problem Language Result Execution time Memory
95267 2019-01-29T09:38:06 Z rkocharyan Palindrome-Free Numbers (BOI13_numbers) C++14
72.5 / 100
2 ms 504 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 20;

int n;
long long dp[N][2];
string s;

long long calc(int pos, int f, int c1, int c2, int c3) {
    if((c2 == c3 && c2 != -1 && c3 != -1) || (c1 == c3 && c1 != -1 && c3 != -1)) return 0;
    if(pos == n) return 1;
    auto &res = dp[pos][f];
    if(res != -1) {
        return res;
    }
    res = 0;
    int lmt = f ? 9 : s[pos] - '0';
    for(int i = 0; i <= lmt; i++) {
        int nf = f;
        if(i < lmt) nf = 1;
        res += calc(pos + 1, nf, c2, c3, i);
    }
    return res;
}

long long solve(string &x) {
    s = x;
    n = (int) x.size();
    memset(dp, -1, sizeof dp);
    return calc(0, 0, -1, -1, -1);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long l, r;
    cin >> l >> r;
    l--;
    string a, b;
    a = to_string(l);
    b = to_string(r);
    cout << solve(b) - solve(a) << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 504 KB Output isn't correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Incorrect 2 ms 416 KB Output isn't correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Correct 2 ms 292 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 424 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Incorrect 2 ms 376 KB Output isn't correct
15 Incorrect 2 ms 376 KB Output isn't correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Incorrect 2 ms 376 KB Output isn't correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 2 ms 376 KB Output isn't correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Incorrect 2 ms 376 KB Output isn't correct
10 Incorrect 2 ms 376 KB Output isn't correct
11 Correct 2 ms 252 KB Output is correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Incorrect 2 ms 376 KB Output isn't correct
14 Incorrect 2 ms 376 KB Output isn't correct
15 Incorrect 2 ms 376 KB Output isn't correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 416 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 252 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 380 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 420 KB Output is correct
42 Correct 2 ms 380 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 2 ms 376 KB Output is correct