답안 #786772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786772 2023-07-18T12:43:29 Z serifefedartar Palindrome-Free Numbers (BOI13_numbers) C++17
54.1667 / 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

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;
}

int main() {
    fast
    ll a, b;
    cin >> a >> b;
    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 340 KB Output isn't correct
3 Correct 1 ms 320 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 0 ms 320 KB Output isn't correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 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 340 KB Output isn't correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Incorrect 1 ms 212 KB Output isn't correct
19 Correct 1 ms 212 KB Output is correct
20 Incorrect 1 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 316 KB Output isn't correct
8 Incorrect 1 ms 212 KB Output isn't correct
9 Incorrect 1 ms 212 KB Output isn't correct
10 Incorrect 1 ms 320 KB Output isn't correct
11 Correct 1 ms 324 KB Output is correct
12 Incorrect 0 ms 212 KB Output isn't correct
13 Incorrect 1 ms 212 KB Output isn't correct
14 Incorrect 1 ms 212 KB Output isn't correct
15 Incorrect 0 ms 340 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 260 KB Output is correct
25 Correct 1 ms 340 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 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Incorrect 1 ms 316 KB Output isn't correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Incorrect 1 ms 212 KB Output isn't correct
36 Incorrect 1 ms 212 KB Output isn't correct
37 Incorrect 1 ms 340 KB Output isn't correct
38 Incorrect 1 ms 212 KB Output isn't correct
39 Incorrect 1 ms 212 KB Output isn't correct
40 Correct 1 ms 212 KB Output is correct
41 Incorrect 1 ms 212 KB Output isn't correct
42 Correct 1 ms 212 KB Output is correct
43 Incorrect 1 ms 212 KB Output isn't correct
44 Incorrect 1 ms 340 KB Output isn't correct
45 Incorrect 1 ms 320 KB Output isn't correct