답안 #488482

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488482 2021-11-19T09:05:24 Z NintsiChkhaidze Palindrome-Free Numbers (BOI13_numbers) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define int ll
using namespace std;
 
string str;
int dp[15][15][25][5];
 
int get(int last2,int last,int len,int sm){
    if (len >= str.size()) return 1;
    if (dp[last2][last][len][sm] != -1) 
        return dp[last2][last][len][sm];
    
    if (sm){
        for (int i = 0; i <= 9; i++){
            if (i != last && i != last2)
                sum += get(last,i,len + 1,1);
        }
    }
    else{
        int l = str[len] - '0',sum = 0;
        for (int i = 0; i < l; i++){
            if (i != last && i != last2)
                sum += get(last,i,len + 1,1);
        }
        
        if (l != last && l != last2)
            sum += get(last,l,len + 1,0);    
    }
    return dp[last2][last][len][sm] = sum;
}
int G(int x){
    if (x < 0) return 0;
    memset(dp, -1, sizeof(dp));
    str = "";
    while(x > 0){
        str+=char((x%10)+'0');
        x/=10;
    }
    
    reverse(str.begin(),str.end());
    int l = str[0] - '0',ans = 1;
    for (int i = 1; i < l; i++)
        ans += get(i,i,1,1);
    ans += get(l,l,1,0);
 
    for (int i = 2; i <= str.size(); i++)
        for (int j=1;j<=9;j++)
            ans += get(j,j,i,1);
 
    return ans;
}
signed main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    ll a,b;
    cin>>a>>b;
    cout<<G(b) - G(a - 1)<<"\n";
}

Compilation message

numbers.cpp: In function 'long long int get(long long int, long long int, long long int, long long int)':
numbers.cpp:13:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     if (len >= str.size()) return 1;
      |         ~~~~^~~~~~~~~~~~~
numbers.cpp:20:17: error: 'sum' was not declared in this scope; did you mean 'sm'?
   20 |                 sum += get(last,i,len + 1,1);
      |                 ^~~
      |                 sm
numbers.cpp:33:39: error: 'sum' was not declared in this scope; did you mean 'sm'?
   33 |     return dp[last2][last][len][sm] = sum;
      |                                       ^~~
      |                                       sm
numbers.cpp: In function 'long long int G(long long int)':
numbers.cpp:50:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 2; i <= str.size(); i++)
      |                     ~~^~~~~~~~~~~~~