답안 #346692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
346692 2021-01-10T17:56:26 Z illequiprogrammat Palindrome-Free Numbers (BOI13_numbers) C++14
13.75 / 100
2 ms 492 KB
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

struct SOLUTION {
    bool vis[30][11][11][2];
    // memo[index][penultimate][end_digit][tight];
    ll memo[30][11][11][2];

    vector<int> digits;

    ll dp(int index, int penultimate, int end, bool tight) {
        if (index == digits.size()) return 1;
        if (vis[index][penultimate][end][tight])
            return memo[index][penultimate][end][tight];
        ll res = 0;
        
        int start = 0;
        int max_next = 9;
        if (tight) max_next = digits[digits.size() - index - 1];
        if (index == 0) start = 1;

        for (int i = start; i <= max_next; i++) {
            if (i != penultimate && i != end) {
                res += dp(index + 1, end, i, tight && i == max_next);
            }
        }


        vis[index][penultimate][end][tight] = true;
        memo[index][penultimate][end][tight] = res;
        return res;
    }

    void get_digits(ll n) {
        while (n != 0) {
            digits.push_back(n%10);
            n /= 10;
        }
    }

    bool is_palindrome() {
        bool res = false;
        for (int i = 0; i < digits.size()-1; i++) {
            if (digits[i] == digits[i+1]) res = true;
        }
        for (int i = 0; i < digits.size()-2; i++) {
            if (digits[i] == digits[i+2]) res = true;
        }
        return res;
    }

};

int main() {
    int a, b;
    SOLUTION l_bound;
    SOLUTION u_bound;
    cin >> a >> b;
    l_bound.get_digits(a);
    ll lres = l_bound.dp(0, 0, 11, true);
    u_bound.get_digits(b);
    ll ures = u_bound.dp(0, 0, 11, true);
    if (l_bound.is_palindrome()) {
        cout << ures - lres << endl;
    } else {
        cout << ures - lres + 1 << endl;
    }
}

Compilation message

numbers.cpp: In member function 'll SOLUTION::dp(int, int, int, bool)':
numbers.cpp:15:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         if (index == digits.size()) return 1;
      |             ~~~~~~^~~~~~~~~~~~~~~~
numbers.cpp: In member function 'bool SOLUTION::is_palindrome()':
numbers.cpp:46:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (int i = 0; i < digits.size()-1; i++) {
      |                         ~~^~~~~~~~~~~~~~~~~
numbers.cpp:49:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (int i = 0; i < digits.size()-2; i++) {
      |                         ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Incorrect 1 ms 364 KB Output isn't correct
4 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 2 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Incorrect 1 ms 364 KB Output isn't correct
20 Incorrect 1 ms 364 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Incorrect 1 ms 364 KB Output isn't correct
6 Correct 1 ms 364 KB Output is correct
7 Incorrect 1 ms 364 KB Output isn't correct
8 Incorrect 1 ms 364 KB Output isn't correct
9 Incorrect 1 ms 364 KB Output isn't correct
10 Incorrect 1 ms 364 KB Output isn't correct
11 Correct 1 ms 364 KB Output is correct
12 Incorrect 1 ms 364 KB Output isn't correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Incorrect 1 ms 364 KB Output isn't correct
15 Incorrect 1 ms 364 KB Output isn't correct
16 Incorrect 1 ms 364 KB Output isn't correct
17 Incorrect 1 ms 384 KB Output isn't correct
18 Incorrect 1 ms 364 KB Output isn't correct
19 Incorrect 1 ms 364 KB Output isn't correct
20 Incorrect 1 ms 364 KB Output isn't correct
21 Incorrect 1 ms 364 KB Output isn't correct
22 Incorrect 1 ms 364 KB Output isn't correct
23 Incorrect 1 ms 364 KB Output isn't correct
24 Incorrect 1 ms 364 KB Output isn't correct
25 Incorrect 1 ms 364 KB Output isn't correct
26 Incorrect 1 ms 364 KB Output isn't correct
27 Incorrect 1 ms 364 KB Output isn't correct
28 Incorrect 1 ms 364 KB Output isn't correct
29 Incorrect 1 ms 364 KB Output isn't correct
30 Incorrect 1 ms 364 KB Output isn't correct
31 Incorrect 1 ms 364 KB Output isn't correct
32 Incorrect 1 ms 364 KB Output isn't correct
33 Incorrect 1 ms 364 KB Output isn't correct
34 Incorrect 1 ms 364 KB Output isn't correct
35 Incorrect 1 ms 384 KB Output isn't correct
36 Incorrect 1 ms 364 KB Output isn't correct
37 Incorrect 1 ms 364 KB Output isn't correct
38 Incorrect 1 ms 364 KB Output isn't correct
39 Incorrect 1 ms 364 KB Output isn't correct
40 Incorrect 1 ms 364 KB Output isn't correct
41 Incorrect 1 ms 364 KB Output isn't correct
42 Incorrect 1 ms 364 KB Output isn't correct
43 Incorrect 1 ms 364 KB Output isn't correct
44 Incorrect 1 ms 364 KB Output isn't correct
45 Incorrect 1 ms 364 KB Output isn't correct