답안 #410797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410797 2021-05-23T18:21:37 Z Victor Palindrome-Free Numbers (BOI13_numbers) C++17
3.75 / 100
2 ms 372 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;

const int INF = 1'000'000'007;

int n;
string lo, hi;
ll memo[20][11][11][2][2];

ll dp(int num, int prev, int befprev, bool l_bound, bool u_bound) {
    if (num == n) return 1;

    ll &ans = memo[num][prev][befprev][l_bound][u_bound];
    if (ans != -1) return ans;

    ans = 0;
    l_bound = 0;

    int start = l_bound ? lo[num] - '0' : 0, stop = u_bound ? hi[num] - '0' + 1 : 10;
    if (!num&&n!=sz(lo)) start = max(start, 1);

    rep(i, start, stop) {
        if (i == prev || i == befprev) continue;

        bool nl_bound = l_bound;
        if (nl_bound) nl_bound = i == lo[num] - '0';
        bool nu_bound = u_bound;
        if (nu_bound) nu_bound = i == hi[num] - '0';

        ans += dp(num + 1, i, prev, l_bound & (i == lo[num] - '0'), u_bound & (i == hi[num] - '0'));
    }

    return ans;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    ll l, h, ans = 0;

    cin >> l >> h;

    lo = to_string(l);
    hi = to_string(h);

    rep(i, sz(lo), sz(hi) + 1) {
        memset(memo, -1, sizeof(memo));
        n = i;
        ans += dp(0, 10, 10, i == sz(lo), i == sz(hi));
    }
    cout << ans << endl;
    return 0;
}

Compilation message

numbers.cpp: In function 'll dp(int, int, int, bool, bool)':
numbers.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     if (!num&&n!=sz(lo)) start = max(start, 1);
      |                ^
numbers.cpp: In function 'int main()':
numbers.cpp:5:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(i, a, b) for (int i = a; i < (b); ++i)
      |                                        ^
numbers.cpp:66:5: note: in expansion of macro 'rep'
   66 |     rep(i, sz(lo), sz(hi) + 1) {
      |     ^~~
numbers.cpp:69:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         ans += dp(0, 10, 10, i == sz(lo), i == sz(hi));
      |                                ^
numbers.cpp:69:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         ans += dp(0, 10, 10, i == sz(lo), i == sz(hi));
      |                                             ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Correct 1 ms 332 KB Output is correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Incorrect 1 ms 332 KB Output isn't correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Incorrect 1 ms 332 KB Output isn't correct
11 Incorrect 1 ms 332 KB Output isn't correct
12 Incorrect 1 ms 332 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Correct 1 ms 332 KB Output is correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Incorrect 1 ms 332 KB Output isn't correct
18 Correct 1 ms 332 KB Output is correct
19 Incorrect 1 ms 332 KB Output isn't correct
20 Incorrect 1 ms 332 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Incorrect 1 ms 332 KB Output isn't correct
7 Incorrect 1 ms 332 KB Output isn't correct
8 Incorrect 1 ms 332 KB Output isn't correct
9 Incorrect 1 ms 372 KB Output isn't correct
10 Incorrect 1 ms 332 KB Output isn't correct
11 Incorrect 1 ms 332 KB Output isn't correct
12 Incorrect 1 ms 332 KB Output isn't correct
13 Incorrect 1 ms 332 KB Output isn't correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Incorrect 1 ms 332 KB Output isn't correct
16 Incorrect 1 ms 332 KB Output isn't correct
17 Incorrect 1 ms 332 KB Output isn't correct
18 Incorrect 1 ms 328 KB Output isn't correct
19 Incorrect 1 ms 332 KB Output isn't correct
20 Incorrect 1 ms 332 KB Output isn't correct
21 Incorrect 1 ms 332 KB Output isn't correct
22 Incorrect 1 ms 332 KB Output isn't correct
23 Incorrect 1 ms 332 KB Output isn't correct
24 Incorrect 1 ms 332 KB Output isn't correct
25 Incorrect 1 ms 332 KB Output isn't correct
26 Incorrect 1 ms 332 KB Output isn't correct
27 Incorrect 1 ms 332 KB Output isn't correct
28 Incorrect 1 ms 332 KB Output isn't correct
29 Incorrect 1 ms 332 KB Output isn't correct
30 Incorrect 1 ms 332 KB Output isn't correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Incorrect 1 ms 268 KB Output isn't correct
33 Incorrect 1 ms 332 KB Output isn't correct
34 Incorrect 1 ms 332 KB Output isn't correct
35 Incorrect 1 ms 332 KB Output isn't correct
36 Incorrect 1 ms 332 KB Output isn't correct
37 Incorrect 2 ms 332 KB Output isn't correct
38 Incorrect 1 ms 332 KB Output isn't correct
39 Incorrect 1 ms 332 KB Output isn't correct
40 Incorrect 1 ms 332 KB Output isn't correct
41 Incorrect 1 ms 332 KB Output isn't correct
42 Incorrect 1 ms 332 KB Output isn't correct
43 Incorrect 1 ms 332 KB Output isn't correct
44 Incorrect 1 ms 332 KB Output isn't correct
45 Incorrect 1 ms 332 KB Output isn't correct