답안 #786793

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786793 2023-07-18T12:51:26 Z serifefedartar Palindrome-Free Numbers (BOI13_numbers) C++17
72.5 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MAXN 100005
#define int long long

ll count(string x) {
    int len = x.length();

    vector<vector<vector<int>>> dp(11, vector<vector<int>>(11, vector<int>(2, 0)));
    dp[10][10][0] = 1;
    for (int i = 0; i < len; i++) {
        vector<vector<vector<int>>> new_dp(11, vector<vector<int>>(11, vector<int>(2, 0)));
        for (auto smaller : {false, true}) {
            for (int second_last = 0; second_last <= 10; second_last++) {
                for (int last_digit = 0; last_digit <= 10; last_digit++) {
                    for (int digit = 0; digit < 10; digit++) {
                        if (!smaller && digit > x[i]-'0')
                            break;
                        if (digit == last_digit || digit == second_last)
                            continue;
                        new_dp[digit][last_digit][smaller || digit < x[i]-'0'] += dp[last_digit][second_last][smaller];
                    }
                }
            }
        }
        dp = new_dp;
    }
    
    ll ans = 0;
    for (int second_last = 0; second_last <= 10; second_last++)
        for (int last_digit = 0; last_digit <= 10; last_digit++)
            ans += dp[last_digit][second_last][0] + dp[last_digit][second_last][1];

    return ans;
}
signed main() {
    fast
    ll a, b;
    cin >> a >> b;
    if (a == 0) {
        string strB = to_string(b);
        cout << count(strB) << endl;
    } else {
        string strA = to_string(a-1), strB = to_string(b);
        ll ans = count(strB) - count(strA);
        cout << ans << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Incorrect 1 ms 212 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Incorrect 0 ms 212 KB Output isn't correct
10 Incorrect 1 ms 212 KB Output isn't correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Incorrect 0 ms 212 KB Output isn't correct
14 Incorrect 0 ms 212 KB Output isn't correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct