답안 #488469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488469 2021-11-19T08:01:34 Z NintsiChkhaidze Palindrome-Free Numbers (BOI13_numbers) C++14
컴파일 오류
0 ms 0 KB
#include <iostream>
#define pb push_back
#define s second
#define f first
#define ll long long
using namespace std;
 
string str;
int dp[15][15][25][5],SIZE;

int get(int last2,int last,int len,int sm){
    if (len >= SIZE) return 1;
    if (dp[last2][last][len][sm] != -1) 
        return dp[last2][last][len][sm];
    
    int l = str[len] - '0',sum = 0;
    if (sm){
        for (int i = 0; i <= 9; i++){
            if (i != last && i != last2)
                sum += get(last,i,len + 1,1);
        }
    }
    else{
        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;
}
void clear(){
    for (int i = 0; i <= 9; i++)
        for (int j = 0; j <= 9; j++)
            for (int z = 0; z<=20; z++)
                dp[i][j][z][0] = dp[i][j][z][1] = -1;
}
int G(int x){
    if (x < 0) return 0;
    clear();
    str = "";
    while(x){
        str+=(x%10)+'0';
        x/=10;
    }
    
    reverse(str.begin(),str.end());
    int l = str[0] - '0',ans = 0;
    SIZE = str.size();
    for (int i = 1; i < l; i++)
        ans += get(i,i,1,1);
    
    ans += get(l,l,1,0);
    clear();
    for (int i = 2; i < str.size() - 1; i++)
        SIZE = i;
        for (int j = 1; j <= 9; j++)
            ans += get(j,j,1,1);
    return ans;
}
signed main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    freopen("output.txt", "w", stdout);
    ll a,b;
    cin>>a>>b;
    cout<<G(b) - G(a - 1)<<"\n";
}

Compilation message

numbers.cpp: In function 'int G(int)':
numbers.cpp:49:5: error: 'reverse' was not declared in this scope
   49 |     reverse(str.begin(),str.end());
      |     ^~~~~~~
numbers.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for (int i = 2; i < str.size() - 1; i++)
      |                     ~~^~~~~~~~~~~~~~~~
numbers.cpp:57:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   57 |     for (int i = 2; i < str.size() - 1; i++)
      |     ^~~
numbers.cpp:59:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   59 |         for (int j = 1; j <= 9; j++)
      |         ^~~
numbers.cpp: In function 'int main()':
numbers.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~