답안 #739677

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
739677 2023-05-11T02:24:37 Z Charizard2021 Palindrome-Free Numbers (BOI13_numbers) C++17
100 / 100
1 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
long long val1;
long long powers10[20];
long long dp[20][11][11][2];
long long solveBasic(long long d, long long p1, long long p2, long long isroot){
    if(d == -1){
        return 1;
    }
    if(dp[d][p1][p2][isroot]){
        return dp[d][p1][p2][isroot];
    }
    long long ans = 0;
    for (long long i = 0; i < 10; i++) {
        if(isroot && i == 0){
            continue;
        }
        if(i != p1 && i != p2){
            ans += solveBasic(d - 1, p2, i, 0);
        }
    }
    return dp[d][p1][p2][isroot] = ans;
}

long long countLeqPow(long long d, long long p1, long long p2, long long isroot){
    if(d == -1){
        return 1;
    }
    long long ans = 0;
    for (long long i = 0; i < 10; i++) {
        if(isroot && i == 0){
            continue;
        }
        if((val1 / powers10[d]) % 10 < i){
            break;
        }
        if(i != p1 && i != p2){
            if((val1 / powers10[d]) % 10 == i){
                ans += countLeqPow(d - 1, p2, i, 0);
                break;
            }
            else ans += solveBasic(d-1,p2,i,0);
        }
    }
    return ans;
}
long long countLeq(long long x){
    if(x == -1){
        return 0;
    }
    val1 = x;
    long long ans = 0;
    long long i, bount = (long long)(lower_bound(powers10,powers10 + 19, x + 1) - powers10);

    for (i=0; i<bount; i++) {
        ans += solveBasic(i - 1, 10, 10, 1);
    }
    ans += countLeqPow(bount - 1, 10, 10, 1);
    return ans;
}
int main(){
    long long a, b;
    cin >> a >> b;
    powers10[0] = 1;
    for(long long i = 1; i < 19; i++){
        powers10[i] = powers10[i-1] * 10;
    }
    cout << countLeq(b) - countLeq(a - 1) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 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 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 0 ms 300 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 300 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 304 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 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 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 308 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 296 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 340 KB Output is correct
43 Correct 1 ms 304 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct