답안 #755477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
755477 2023-06-10T07:09:33 Z drdilyor Palindrome-Free Numbers (BOI13_numbers) C++17
72.5 / 100
9 ms 11860 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    string a, b;
    cin >> a >> b;
    string oa = a;

    vector<vector<vector<vector<ll>>>> memo;

    auto dp = [&](auto& dp, string& s, int i, char prev, char cur, bool free)->ll{
        if (i == (int)s.size()) return 1;
        ll& key = memo[free][i][prev][cur];
        if (key != -1) return key;
        ll res = 0;
        for (char c = '0'; c <= '9'; c++) {
            if (c == prev || c == cur) continue;
            if (free || c <= s[i]) {
                res += dp(dp, s, i+1, cur, c, free || c < s[i]);
            }
        }
        return key = res;
    };

    auto calc = [&](string s) {
        if (s == "0") return 1ll;
        memo = vector(2, vector(s.size(), vector(128, vector(128, -1ll))));
        return dp(dp, s, 0, '-', '-', false) + 1ll;
    };

    ll res = calc(b) - calc(a) + 1;

    for (int i = 1; i < (int)a.size(); i++){
        if (a[i] == a[i-1]) {res--; break; }
        if (i >1 && a[i] == a[i-2]) {res--; break; }
    }
    cout << res << '\n';



    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1620 KB Output isn't correct
2 Incorrect 1 ms 1620 KB Output isn't correct
3 Correct 7 ms 11016 KB Output is correct
4 Incorrect 2 ms 2772 KB Output isn't correct
5 Incorrect 1 ms 1364 KB Output isn't correct
6 Incorrect 1 ms 1620 KB Output isn't correct
7 Incorrect 1 ms 1620 KB Output isn't correct
8 Incorrect 1 ms 1620 KB Output isn't correct
9 Correct 1 ms 1748 KB Output is correct
10 Correct 1 ms 2388 KB Output is correct
11 Correct 3 ms 3668 KB Output is correct
12 Correct 2 ms 3668 KB Output is correct
13 Correct 1 ms 2388 KB Output is correct
14 Incorrect 2 ms 2772 KB Output isn't correct
15 Incorrect 2 ms 2772 KB Output isn't correct
16 Correct 3 ms 4416 KB Output is correct
17 Correct 3 ms 4436 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 6 ms 11016 KB Output is correct
20 Incorrect 2 ms 2772 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6356 KB Output is correct
2 Correct 6 ms 11732 KB Output is correct
3 Correct 6 ms 11732 KB Output is correct
4 Correct 6 ms 11732 KB Output is correct
5 Incorrect 4 ms 4580 KB Output isn't correct
6 Correct 3 ms 6356 KB Output is correct
7 Incorrect 3 ms 4308 KB Output isn't correct
8 Incorrect 2 ms 4308 KB Output isn't correct
9 Incorrect 2 ms 3412 KB Output isn't correct
10 Incorrect 2 ms 3844 KB Output isn't correct
11 Correct 4 ms 6356 KB Output is correct
12 Incorrect 2 ms 4564 KB Output isn't correct
13 Incorrect 2 ms 4308 KB Output isn't correct
14 Incorrect 3 ms 4564 KB Output isn't correct
15 Incorrect 2 ms 4180 KB Output isn't correct
16 Correct 8 ms 11684 KB Output is correct
17 Correct 6 ms 11732 KB Output is correct
18 Correct 7 ms 11732 KB Output is correct
19 Correct 7 ms 11768 KB Output is correct
20 Correct 7 ms 11732 KB Output is correct
21 Correct 6 ms 11720 KB Output is correct
22 Correct 7 ms 11092 KB Output is correct
23 Correct 7 ms 11732 KB Output is correct
24 Correct 7 ms 11668 KB Output is correct
25 Correct 9 ms 11720 KB Output is correct
26 Correct 7 ms 11732 KB Output is correct
27 Correct 6 ms 11732 KB Output is correct
28 Correct 7 ms 11732 KB Output is correct
29 Correct 7 ms 11732 KB Output is correct
30 Correct 8 ms 11860 KB Output is correct
31 Correct 7 ms 11732 KB Output is correct
32 Correct 7 ms 11732 KB Output is correct
33 Correct 9 ms 11092 KB Output is correct
34 Correct 7 ms 11732 KB Output is correct
35 Correct 7 ms 11732 KB Output is correct
36 Correct 7 ms 11732 KB Output is correct
37 Correct 7 ms 11072 KB Output is correct
38 Correct 7 ms 11732 KB Output is correct
39 Correct 7 ms 11764 KB Output is correct
40 Correct 7 ms 11732 KB Output is correct
41 Correct 7 ms 11676 KB Output is correct
42 Correct 6 ms 11656 KB Output is correct
43 Correct 6 ms 11732 KB Output is correct
44 Correct 7 ms 11752 KB Output is correct
45 Correct 7 ms 11732 KB Output is correct