답안 #629896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629896 2022-08-15T10:33:23 Z typ_ik Palindrome-Free Numbers (BOI13_numbers) C++17
37.5 / 100
2 ms 340 KB
#include <bits/stdc++.h>

#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define watch(x) cout << (#x) << " = " << x << '\n'
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const int LEN = 20;
const int NUMBER_SIZE = 11;
const int WAS_SMALLER = 2;

ll dp[LEN][NUMBER_SIZE][NUMBER_SIZE][WAS_SMALLER];

void init() {
    for (int i = 0; i < LEN; i++)
        for (int pl = 0; pl < NUMBER_SIZE; pl++)
            for (int l = 0; l < NUMBER_SIZE; l++)
                for (int w = 0; w < 2; w++)
                    dp[i][pl][l][w] = -1;
}

vector <int> d;

ll get(int pos, int pl, int l, int was) {
    if (pos == d.size())
        return dp[pos][pl][l][was] = 1;

    if (dp[pos][pl][l][was] != -1)
        return dp[pos][pl][l][was];

    int mx = d[pos];
    if (was)
        mx = 9;

    int res = 0;

    for (int nxt = 0; nxt <= mx; nxt++) {
        if (nxt == pl || nxt == l)
            continue;

        res += get(pos + 1, l, nxt, was | (nxt < d[pos]));
    }

    return dp[pos][pl][l][was] = res;
}

ll calc(ll x) {
    d.clear();
    while (x) d.push_back(x % 10), x /= 10;
    reverse(all(d));
    init();
    get(0, 10, 10, 0);
    return dp[0][10][10][0];
}

void solve() {
    ll a, b;
    cin >> a >> b;
    cout << calc(b) - calc(a - 1) << '\n';
}

main() {
    boost;
    solve();
    return 0;
}

Compilation message

numbers.cpp: In function 'long long int get(int, int, int, int)':
numbers.cpp:28:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if (pos == d.size())
      |         ~~~~^~~~~~~~~~~
numbers.cpp: At global scope:
numbers.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 1 ms 328 KB Output isn't correct
3 Correct 1 ms 324 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Incorrect 0 ms 324 KB Output isn't correct
7 Incorrect 1 ms 328 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 328 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 340 KB Output is correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Incorrect 1 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't 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 328 KB Output isn't correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Correct 1 ms 340 KB Output is correct
12 Incorrect 1 ms 324 KB Output isn't correct
13 Incorrect 1 ms 328 KB Output isn't correct
14 Incorrect 1 ms 328 KB Output isn't correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Incorrect 1 ms 340 KB Output isn't correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Incorrect 1 ms 340 KB Output isn't correct
22 Correct 1 ms 332 KB Output is correct
23 Incorrect 1 ms 340 KB Output isn't correct
24 Correct 1 ms 340 KB Output is correct
25 Incorrect 1 ms 340 KB Output isn't correct
26 Incorrect 1 ms 340 KB Output isn't correct
27 Incorrect 1 ms 324 KB Output isn't correct
28 Incorrect 1 ms 340 KB Output isn't correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Correct 1 ms 340 KB Output is correct
33 Incorrect 1 ms 340 KB Output isn't correct
34 Correct 1 ms 328 KB Output is correct
35 Incorrect 1 ms 340 KB Output isn't correct
36 Incorrect 1 ms 328 KB Output isn't correct
37 Incorrect 1 ms 328 KB Output isn't correct
38 Incorrect 1 ms 340 KB Output isn't correct
39 Incorrect 1 ms 332 KB Output isn't correct
40 Correct 1 ms 340 KB Output is correct
41 Incorrect 1 ms 340 KB Output isn't correct
42 Correct 2 ms 340 KB Output is correct
43 Incorrect 1 ms 340 KB Output isn't correct
44 Incorrect 1 ms 340 KB Output isn't correct
45 Incorrect 1 ms 340 KB Output isn't correct