답안 #755479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
755479 2023-06-10T07:12:00 Z drdilyor Palindrome-Free Numbers (BOI13_numbers) C++17
15.8333 / 100
21 ms 25428 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<vector<ll>>>>> memo;

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

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

    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 2 ms 3156 KB Output isn't correct
2 Incorrect 2 ms 3156 KB Output isn't correct
3 Incorrect 14 ms 23892 KB Output isn't correct
4 Incorrect 4 ms 5972 KB Output isn't correct
5 Incorrect 2 ms 2444 KB Output isn't correct
6 Incorrect 2 ms 3156 KB Output isn't correct
7 Incorrect 2 ms 3156 KB Output isn't correct
8 Incorrect 2 ms 3156 KB Output isn't correct
9 Incorrect 2 ms 3284 KB Output isn't correct
10 Incorrect 3 ms 4820 KB Output isn't correct
11 Incorrect 4 ms 7764 KB Output isn't correct
12 Incorrect 4 ms 7764 KB Output isn't correct
13 Incorrect 3 ms 4820 KB Output isn't correct
14 Incorrect 3 ms 5972 KB Output isn't correct
15 Incorrect 3 ms 5972 KB Output isn't correct
16 Correct 5 ms 9124 KB Output is correct
17 Incorrect 5 ms 9172 KB Output isn't correct
18 Correct 0 ms 212 KB Output is correct
19 Incorrect 15 ms 23908 KB Output isn't correct
20 Incorrect 4 ms 5980 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 13524 KB Output isn't correct
2 Correct 20 ms 25300 KB Output is correct
3 Incorrect 16 ms 25376 KB Output isn't correct
4 Incorrect 17 ms 25368 KB Output isn't correct
5 Incorrect 6 ms 9300 KB Output isn't correct
6 Incorrect 8 ms 13628 KB Output isn't correct
7 Incorrect 6 ms 8788 KB Output isn't correct
8 Incorrect 5 ms 8788 KB Output isn't correct
9 Incorrect 5 ms 6868 KB Output isn't correct
10 Incorrect 4 ms 7892 KB Output isn't correct
11 Incorrect 11 ms 13604 KB Output isn't correct
12 Incorrect 5 ms 9300 KB Output isn't correct
13 Incorrect 7 ms 8772 KB Output isn't correct
14 Incorrect 6 ms 9300 KB Output isn't correct
15 Incorrect 6 ms 8428 KB Output isn't correct
16 Incorrect 17 ms 25300 KB Output isn't correct
17 Incorrect 17 ms 25300 KB Output isn't correct
18 Incorrect 19 ms 25364 KB Output isn't correct
19 Correct 15 ms 25276 KB Output is correct
20 Correct 15 ms 25300 KB Output is correct
21 Incorrect 19 ms 25272 KB Output isn't correct
22 Correct 16 ms 23892 KB Output is correct
23 Correct 18 ms 25296 KB Output is correct
24 Correct 17 ms 25300 KB Output is correct
25 Incorrect 17 ms 25312 KB Output isn't correct
26 Incorrect 18 ms 25280 KB Output isn't correct
27 Correct 15 ms 25300 KB Output is correct
28 Correct 15 ms 25300 KB Output is correct
29 Incorrect 20 ms 25288 KB Output isn't correct
30 Incorrect 17 ms 25264 KB Output isn't correct
31 Incorrect 15 ms 25428 KB Output isn't correct
32 Incorrect 17 ms 25312 KB Output isn't correct
33 Incorrect 15 ms 23892 KB Output isn't correct
34 Incorrect 17 ms 25300 KB Output isn't correct
35 Incorrect 17 ms 25300 KB Output isn't correct
36 Incorrect 16 ms 25276 KB Output isn't correct
37 Incorrect 16 ms 23892 KB Output isn't correct
38 Incorrect 17 ms 25300 KB Output isn't correct
39 Incorrect 17 ms 25284 KB Output isn't correct
40 Incorrect 19 ms 25276 KB Output isn't correct
41 Incorrect 16 ms 25300 KB Output isn't correct
42 Incorrect 18 ms 25276 KB Output isn't correct
43 Incorrect 21 ms 25268 KB Output isn't correct
44 Incorrect 17 ms 25292 KB Output isn't correct
45 Incorrect 18 ms 25352 KB Output isn't correct