답안 #739676

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
739676 2023-05-11T02:24:21 Z Charizard2021 Palindrome-Free Numbers (BOI13_numbers) C++17
컴파일 오류
0 ms 0 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;
}
long long 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";
}

Compilation message

cc1plus: error: '::main' must return 'int'